Print the first line of a file C programming
- by Pedro
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");
}