Quote:
Originally posted by wolk
why complicate the simple stuff...?
why don't u use :
scanf("%s",&x );
I certainly agree with the sentiment "why complicate the simple stuff?". Still I have to say that fgets is, to me, a much simpler routine to understand than scanf. And even if it wasn't, scanf will do more work than fgets to acquire that string. Finally, the fgets solution will prevent buffer overflow. You will need to use something like:
scanf("%255s", &x);
to render this safe. And if the buffer is not a constant size you will need to dynamically build the format string that you pass to scanf.
scanf is great when you have a complex set of data, but to just read a single string, I would always go with fgets. Even for your second example, I might tend to go with fgets and atoi. But if it was, say, two integers and a string, I would use the scanf routine.