I need my program to read a text file that contains 10 names. Ask the user to enter a name, if the name exists in the file print “The name is found”, if the name is not there print “The name is NOT found”
I have a word document with all the names saved as "lab" in the same file as my program.
So far I have
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main ()
{
char *names;
char name[20];
FILE * fin, * fout;
printf("Enter a name\n");
scanf("%s", &name);
fout = fopen("lab.txt", "r");
if ((fout = fopen("lab.txt", "r")) == NULL)
printf("error");
fprintf(fout, "%s", names);
if (name == names){
printf("Name is found");
}else{
printf("Name is not found");
}
fclose(fout);
return 0;
}
but no matter what name I type it says "Name is not found"