Print the first line of a file C programming

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/22 23:43 UTC
Read the original article Hit count: 168

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("ERROR\n");
              return ;
              }

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


                        free(fp);
                        }

I want to open a file and print the first line. the problem here is in while(fp='\n'), what i'm doing wrong.

How can i make a function that recognize the first char from a file...

like:

FILE *arq;
char info[20];
 arq=fopen("trabalho.txt","r");
 if(fp==NULL){
              printf("ERROR\n");
              return ;
              }
if(fp[0]='-'){ //check if the first element is a '-'
 printf("It's info\n");
 }

© Stack Overflow or respective owner

Related posts about c

    Related posts about fopen