d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Simple C Problem, Need Help Asap
Add Reply New Topic New Poll
Member
Posts: 2,930
Joined: May 4 2007
Gold: 1,028.00
Feb 9 2017 05:41pm
I've got a project due @ 8pm tonight, its 5:40pm now.

I've got it 90% complete, except for one bit of functionality. I'm supposed to read an input file that has multiple sudoku 4x4 boards in it, and check them for proper formatting/validity.

My program does all of that, except for only one game board. I'm having a lot of trouble figuring out how to make it read multiple boards. Can anyone help me?

I've looked up MAN pages for fgetc, fgets, getline, fgetf, and some other things, and nothing seems to do what I'm thinking I want to do.

HALP!
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Feb 9 2017 07:27pm
Use a while loop with the condition set to something like "!strcmp(user_input, "quit")" and then simply ask the user for a file name each iteration then run it through your solver. If the user enters "quit" the loop will break exiting your software. User input can be done many ways but I prefer using fgets() on STDIN. This is because you can prevent stack overflows since you can specify the size of your buffer which will hold the filename to parse.

It may look something like this:

Code
#include <headers>

int main() {
char user_input[41] = {0};

printf("Enter a file name to parse or quit\n");
fgets(STDIN, 40, user_input);
while(!strcmp(user_input, "quit") {
//read the file using the user_input varaible as the file name
//run it through your solver functions
printf("Enter a file name to parse or quit\n");
fgets(STDIN, 40, user_input);
}
return 0;
}


This post was edited by AbDuCt on Feb 9 2017 07:31pm
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll