I'm using Ubuntu and I'm also using Geany and CodeBlock as my IDE.
What I'm trying to do is reading a string (like
printf("Enter your name: ");
printf("Your Name is: %s", name);
Enter your name: Barack Obama
Your Name is: Barack
fgets (name, 100, stdin);
100 is the max length of the buffer. You should adjust it as per your need.
scanf ("%[^\n]%*c", name);
 is the scanset character.
[^\n] tells that while the input is not a newline (
'\n') take input. Then with the
%*c it reads the newline character from the input buffer (which is not read), and the
* indicates that this read in input is discarded (assignment suppression), as you do not need it, and this newline in the buffer does not create any problem for next inputs that you might take.
Note you can also use
gets but ....
gets(). Because it is impossible to tell without knowing the data in advance how many characters gets() will read, and because
gets()will continue to store characters past the end of the buffer, it is extremely dangerous to use. It has been used to break computer security. Use