Jump to content

ajuda com ficheiros


micront

Recommended Posts

int main()

{

  FILE * pFile;

  char buffer [100];

  pFile = fopen ("myfile.txt" , "r");

  if (pFile == NULL) perror ("Error opening file");

  else

  {

    while ( ! feof (pFile) )

    {

      fgets (buffer , 100 , pFile);

      fputs (buffer , stdout);

    }

    fclose (pFile);

  }

  return 0;

Ja agora podiam ajudar a compreender estas linhas de codigo,sou iniciante e estou com alguma dificuldade em entender principalmente a parte do ciclo while :wallbash:

Link to comment
Share on other sites

  • 2 weeks later...

FILE * pFile;

  char string [100];

  pFile = fopen ("Lista P.Erdos" , "r");

  if (pFile == NULL) perror ("Erro ao abrir o ficheiro");

  else {

    fgets (string , 100, pFile);

    puts (string);

    fclose (pFile);

  }

    return 0;

fiz este programa para ler linha a linha do ficheiro mas nao estou a conseguir

alguem me pode ajudar

Link to comment
Share on other sites

fiz o seguinte e da me erro segment fault

  FILE * pFile;

  char string [100];

  pFile = fopen ("Lista P.Erdos" , "r");

  if (pFile == NULL) perror ("Erro ao abrir o ficheiro");

  else {

      while(fgets (string , 100, pFile),pFile!=NULL)

      {

          printf("%s\n",pFile);

          pFile=strtok(NULL,",.-");

      puts(string);

  }

    fclose (pFile);

  }

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.