Need some help to read from a file
I am a bit lost trying to read stuff from a file which has been written before.
I want my program to open an already existing file which has my friends names and numbers written like this:
friend1-7372384729
friend2-9374628202
The input to the program will be my friendīs name and the output after searching in the file will be his number.
I have studied these functions: fscanf, fgetc, and fgets and tried to use them but it isnt working , I must be doing something wrong.
Here is the code: I hope it isnt as awful as I think it is
Code:
#include <stdio.h>
#include <string.h>
#define d 25
int main(){
char nom[d],*a; int i=0,n;
FILE *f;
printf("\nIntroduce your friendīs name: ");
gets(nom);
if((f=fopen("telefonos.txt","r"))==NULL) printf("\nError oppening the file");
while((i!=EOF)&&(a!=nom)) i=fscanf(f,"%s",a);
if(i==EOF) {printf("\nIt seems you havenīt got %s number registered",nom);return 0;}
printf("\n%s number is: %d", *a, n);
fclose(f);
return 0;}