fgets()

does anyone knows how to accept a command from a user.. i was wondering to use fgets(), but got no idea how to start it...

If you are planning to read from the 'stdin' [Keyboard];

fgets(l_str, 255, stdin);

If you're wanting to get input from a user (interactive script)...then you can use 'print and read'
see man pages for detail.

why complicate the simple stuff...?
why don't u use :

scanf("%s",&x );

where x is declared as pointer to char (char* x)
I assume that the command is in string format, if it is a int, it will look like:

scanf("%d",&x);

where x is a int

good luck!
by wolk!

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.