Reading in line by line in C? I am having trouble with one programming problem: Write a complete program that reads in the player database of project 1 and prints out all the players who have made $6.0 millions or higher in the following format: Quarterback Donovan McNabb makes $12.00 millions - The file being read from is players.txt which is in the format like this 7869 QB Brees Drew 10.4 10 260. 3560 QB Brady Tom 9.6 11 240 The PROBLEM I am having is reading in these lines. I can attach my whole code, but the main section of my code is this: i=0; while(fscanf(players,"%d %c%c\n", &p
i=0; while(fscanf(players,"%d %c%c\n", &playerID, &position[i], &position[i+1])){ printf("%d %c%c\n", playerID, position[i], position[i+1]); } //This only prints out 7869 QB I know this is very inefficient since you are reading in every character. So i tried to change the two %c%c to a string %s but i keep getting a segmentation error(core dumped). I read ppl using fgets and other stuff but I have to use fscanf etc I am lost and have no idea how to read in each line. I hope someone can help.Thanks!
Are you sure, when you used "%s" instead of "%c%c" that you wrote "position" as parameter instead of "&position"?
Join our real-time social learning platform and learn together with your friends!