d2jsp Forums > Programmer's Haven > C/C++/C# > Simple C Problem, Need Help Asap
Add Reply New Topic New Poll
#1 Feb 9 2017 05:41pm
Group: Member
Posts: 2,724
Joined: May 4 2007
Gold: 0.00
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.

#2 Feb 9 2017 07:27pm
Group: Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 30%
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:

#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 C/C++/C# Topic List
Add Reply New Topic New Poll