Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

v.avancini

Posição do ponteiro em arquivos c++

Recommended Posts

A função a seguir deveria colocar o ponteiro na décima posição no aquivo e escrever a partir dele, porém isto não ocorre, alguém para me ajudar?

void EstagioAluno::writeEA (ofstream &arq)
{
	char buffer [1000];
	char aux [20];
	short length;
	itoa(matricula, buffer, 10);
	strcat(buffer, "|");
	strcat(buffer, nomeCompleto);
	strcat(buffer, "|");
	strcat(buffer, tipoEstagio);
	strcat(buffer, "|");
	strcat(buffer, nomeEmpresa);
	strcat(buffer, "|");
	strcat(buffer, cnpj);
	strcat(buffer, "|");
	strcat(buffer, nomeSupervisor);
	strcat(buffer, "|");
	strcat(buffer, dataInicio);
	strcat(buffer, "|");
	strcat(buffer, dataFim);
	strcat(buffer, "|");
	strcat(buffer, dataEntregaRelatorioParcial);
	strcat(buffer, "|");
	strcat(buffer, situacao);
	strcat(buffer, "|");
	itoa(horasPrevistas, aux, 10);//converte int em char na base 10 e passa para aux
	strcat(buffer, aux);
	strcat(buffer, "|");
	itoa(horasTotalizadas, aux, 10);//converte int em char na base 10 e passa para aux
	strcat(buffer, aux);
	strcat(buffer, "|");
	strcat(buffer, parecerFinal);
	strcat(buffer, "|");
	length = (short) strlen(buffer);		
	arq.seekp(9, ios::end);//reserva os 10 primeiros bytes para o cabeçalho
	cout << arq.tellp() << endl;
	cout << buffer << endl;
	//campo flag de excluido (avail list)
	arq.write((char*)&length, sizeof(length));
	arq.write(buffer, length);
	cout << arq.tellp() << endl;
}

e dessa forma eu abro o arquivo na main e passo para a função:

case 1:
	arq1.open ("estagios.txt", ios::binary|ios::app);	
	if (!arq1.good())
	{
		cerr<< "Não foi possível abrir o arquivo."<<endl;
					exit(1);
					
	}
	ea.PreencherEA();
	ea.writeEA(arq1);
	arq1.close();
	break;

Compartilhar este post


Link para o post
Compartilhar em outros sites

  • Conteúdo Similar

    • Por ILR master
      Fala galera.
      Espero que todos estejam bem.
      Seguinte: Tenho um arquivo xml onde alguns campos estão com : (dois pontos), como o exemplo abaixo:
       
      <item>
      <title>
      d sa dsad sad sadasdas
      </title>
      <link>
      dsadas dsa sad asd as dsada
      </link>
      <pubDate>sadasdasdsa as</pubDate>
      <dc:creator>
      d sad sad sa ad as das
      </dc:creator>
      </item>
       
      Meu código:
       
      $link = "noticias.xml"; 
      $xml = simplexml_load_file($link); 
      foreach($xml -> channel as $ite) {     
           $titulo = $ite -> item->title;
           $urltitulo = $ite -> item->link;
           print $urltitulo = $ite -> item->dc:creator;
      } //fim do foreach
      ?>
       
      Esse campo dc:creator eu não consigo ler. Como faço?
       
      Agradeço quem puder me ajudar.
       
      Abs
       
       
    • Por Sharank
      Strcat Function In C++
       
      I'm new to C and C++ programming, can anyone give me a hint on what I'm doing wrong here. I'm trying to write to concat function that takes to pointers to chars and concatenates the second to the first. The code does do that, but the problem is that it adds a bunch of junk at the end.
       
      For instance, when passing the arguments - "green" and "blue", the output will be "greenblue" plus a bunch of random characters. I also wrote the strlen function that strcat uses, which I will provide below it for reference. I'm using the online compiler at InterviewBit The exact instructions and specification is this:
       
      int main(int argc, char** argv)
      {
      const int MAX = 100;
       
      char s1[MAX];
      char s2[MAX];
       
      cout << "Enter your first string up to 99 characters. ";
      cin.getline(s1, sizeof(s1));
      int size_s1 = strlen(s1);
      cout << "Length of first string is " << size_s1 << "\n";
       
      cout << "Enter your second string up to 99 characters. ";
      cin.getline(s2, sizeof(s2));
      int size_s2 = strlen(s2);
      cout << "Length of second string is " << size_s2 << "\n";
      cout << " Now the first string will be concatenated with the second
      string ";
      char* a = strcat(s1,s2);
       
      for(int i = 0; i<MAX; i++)
      cout <<a;
       
      // system("pause");
      return 0;
      }
       
      //strcat function to contatenate two strings
      char* strcat(char *__s1, const char *__s2)
      {
      int indexOfs1 = strlen(__s1);
      int s2L = strlen(__s2);
      cout <<s2L << "\n";
      int indexOfs2 = 0;
      do{
      __s1[indexOfs1] = __s2[indexOfs2];
      indexOfs1++;
      indexOfs2++;
      }while(indexOfs2 < s2L);
       
       
      return __s1;
      }
       
      //Returns length of char array
      size_t strlen(const char *__s)
      {
      int count = 0;
      int i;
      for (i = 0; __s != '\0'; i++)
      count++;
      return (count) / sizeof(__s[0]);
       
      }
    • Por roberson abalaid
      #include <stdio.h>
      #include <stdlib.h>
      int arr[3][5];
      int main(){
          
          printf("Favor inserir os dados...\n");
          
          for(int i = 0; i < 3; i++){
              for(int j = 0; j < 5; j++){
                  scanf("%d", &arr[j]);
              }
          }
          
            printf("os valores inseridos foram...\n");
          
          for(int i = 0; i < 3; i++){
              for(int j = 0; j < 5; j++){
                  printf("  %d  ", arr[j]);
              }
              printf("\n");
          }
          return 0;
      }
    • Por Ane_
      Olá gente.
       
      Não consigo abrir o arquivo de desenvolvimento de um aplicativo,
      que foi feito pela themeforest(o template).
      Será que ele não é compatível com as IDE's que eu tô tentando abrir, já tentei no:
       
      Notepad++ Visual Studio (Com o ionic instalado) Android Studio  
      Esse é um dos erros que aparecem:
       
      "the archive not is displayed in the editor because it is either binary or uses unsupported text encoding"
       
    • Por flipmartinz13
      Alguém pode me ajudar nessa questão de C++? não estou conseguindo construir o algorítmo corretamente.

      5.92)    Faça um algoritmo que leia a matrícula, nome, sexo e três notas dos alunos de uma escola e obtenha os seguintes resultados:
      a) A matrícula da aluna que obteve a maior média.
      b) A matrícula do aluno que obteve a menor média.
      c) O percentual de mulheres na turma.
      d) Quantos alunos foram aprovados, independente do sexo.
      e) O percentual de alunas aprovadas.
      Obs.: o flag é uma matrícula igual a 0 (zero).
×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.