Print the first line of a file

Posted by Pedro on Stack Overflow See other posts from Stack Overflow or by Pedro
Published on 2010-04-22T23:39:26Z Indexed on 2010/04/23 0:23 UTC
Read the original article Hit count: 650

Filed under:
|
void cabclh(){
 FILE *fp;
 char *val, aux;
 int i=0;
 char *result, cabeca[60];
 fp=fopen("trabalho.txt","r");
 if(fp==NULL){
              printf("Erro ao abrir o ficheiro\n");
              return ;
              }

 val=(char*)calloc(aux, sizeof(char));
 while(fgetc(fp)=='\n'){
                fgets(cabeca,60,fp);
                printf("%s\n",cabeca);
                }
                fclose(fp);


                        free(fp);
                        }

void infos(){
 FILE *fp;
 char info[100];
 fp=fopen("trabalho.txt","r");
 if(fp==NULL){
              printf("Erro ao abrir o ficheiro\n");
              }
 while(fgetc(fp)=='-'){
                      fgets(info,100,fp);
                        printf("%s\n",info);
                        }
                        fclose(fp);

                        }   

At cabclh i want that the program recognize that the first line is header..but this code doesn't print nothing

At infos i want that he recognize that every lines that begin with '-' are info...

© Stack Overflow or respective owner

Related posts about c

    Related posts about fopen