Originally Posted by
matsp
Well, it's really a question of "don't mix line input and other input functions, unless you are prepared to deal with the consequences". To put that a different way: Choose either scanf() or fgets(). You can always use a mix of fgets() and sscanf().
I started to implement the code as follows:
Code:
int main(void)
{
char cNum[10];
int iNum=0;
char cStr[20];
puts("Enter a number:");
fgets(cNum,10,stdin);
sscanf(cNum,"%d",&iNum);
puts("Enter a string:");
fgets(cStr,20,stdin);
printf("Num=%d\n",iNum);
puts(cStr);
return 0;
}
It seems to be working fine until a longgggg numbers is enter.
What am I doing wrong.
Thank you