This should suffice for simple use
Code:
while ( fscanf(fp,"%d %s %s",&no, fname, lname) != EOF ) {
add(no,fname,lname);
printf("values added......");
}
But this is better
Code:
char buff[BUFSIZ]; // BUFSIZ in stdio.h
while ( fgets( buff, BUFSIZ, fp ) != NULL ) {
if ( sscanf( buff, "%d %s %s", &no, fname, lname) == 3 ) {
add(no,fname,lname);
printf("values added......");
} else {
// invalid line format error
}
}
> then the first %s will read rest of file until a null char is encountered e.g. it will read the space characters between first and surnames.
This is incorrect - %s stops at the first white space (or newline)