i’m new at c.. and still having trouble at the syntax, hope you can help me… cause i’m stuck at this code
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void){
FILE *stream = NULL;
stream = fopen("studentinfo.txt", "a+");
/*some of initialization were used for testing purposes only*/
char arr[5];
char arr2[5];
int i;
char name[3];
char course[5];
printf("enter details: ");
scanf("%s", arr2);
while(!feof(stream)){
fgets(arr, 100, stream);//i am confused if the line capture was stored at arr[0]
if(strcmp(arr, arr2)==0){//i want to compare
printf("success");//testing
}
printf("%s", arr);//i wonder does fgets just overwrites the new line to arr[0]
}
fclose(stream);
getch();
}
thanks guys…
if you have an existing file… and your file has data on it. then you could check if the data you typed is existing on the file or not. i’m not sure if this is what you want.
example if you typed…
loveand the file also contains the exact word…
love(on one line)then it will print “success”.
if the data you typed is not existing on the file, it will be appended on the file (on the next line).