thanks for taking the time to look at it, I´ve changed a few things you told me but some things are new and I don´t really understand how they work foe example what kind of format is %[^-]
I´ve done changes but still isn´t working:
Code:
#include <stdio.h>
#include <string.h>
#define SIZE 25
int main(){
char str1[SIZE]={0},str2[SIZE]={0},n[8]={0}; int i=0,j=0;
FILE *f;
printf("\nIntroduce your friend´s name: ");
gets(str1); puts(str1);
if((f=fopen("telefonos.txt","r"))==NULL) {printf("\nError oppening the file. The program has finished"); return 0;}
while((i!=EOF)&&((strcmp(str1, str2)) != 0)) {i=fscanf(f,"%[^-]-%s", str2[j], n[j]);
++i; ++j;}
if(i==EOF) {printf("\nIt seems you haven´t got %s number registered",str1);return 0;}
printf("\n%s number is: %d", str2, n);
fclose(f);
return 0;}
I have also tried this:
Code:
i=0; strname{0};
while (strname[i]!='-') {strname[i]=fgetc(f);++i;}
if((strcmp(a, nom)) != 0)
{
j=0; strnumber={0};
while(strnumber[j]!='\n'){strnumber[j]=fgetc(f);++j;}
}
but I think that has to be done for every line in the file but I don´t know how to express that in C.
Anyway I´ll be glad if you can keep on helping me