fgets, sscanf, and writing to arrays
Posted
by
alldavidsluck
on Stack Overflow
See other posts from Stack Overflow
or by alldavidsluck
Published on 2013-11-07T20:28:15Z
Indexed on
2013/11/08
3:54 UTC
Read the original article
Hit count: 218
beginner question here, I haven't been able to find examples that relate. I'm working on a C program that will take integer input from stdin using fgets and sscanf, and then write it to an array. However, I'm not sure how to make fgets write to the array.
#define MAXINT 512
char input[MAXINT]
int main(void)
{
int i;
int j;
int count=0;
int retval;
while (1==1) {
fgets(input, MAXINT[count], stdin);
retval = sscanf(input, "%d", &i);
if (retval == 1) {
count = count++;
}
else
if (retval != 1) {
break;
}
}
Would I simply put fgets in a for loop? or is it more complicated than that?
© Stack Overflow or respective owner