How to read formatted string from a text file?

ok so this is how I did it … I just used the fact that ObjC is a superset of C

char personName[256];
char imgFilename[512];
int personNumber;

NSArray *array = [outputString componentsSeparatedByString:@"\n"]; 
int lines = [array count];
FILE *file = fopen([filePath UTF8String],"r");
for (int i = 0; i<lines; i++) {
    fscanf(file,"%d %s %s",&personNumber, personName, imgFilename);
    NSLog(@"From Fscanf %d %s %s",personNumber,personName,imgFilename);
}
fclose(file);

Leave a Comment