In C, space is a normal character, like any other.
What you’re seeing as odd there, is that in fact the function scanf
uses space as an input value separator by default.
If you instead of scanf
use the function fgets
, will have fewer surprises: all characters typed by the user will be transferred to the vector determined by you until a line break (string that depends on the operating system).
In addition, fgets, as well as scanf, adds a character \x00
, that represents the end of the string for most functions in C.
Instead of:
scanf("%s", nome);
Your reading line would look like this:
fgets(nome, 20, stdin);
and you wouldn’t be surprised by spaces, which would be a normal character. In addition, fgets can be used in real systems programs and libraries, which go into production, because it has the maximum string size to be read, and thus avoids buffer overflow problems. The scanf is a very versatile function for reading an arbitrary number of tokens, and even different data types, but it is more difficult to use correctly for simple cases.
So I was wanting to add ' 0' in hand and was not working kkk
– iLuucasD
I hope I’ve helped
– alxwca
The space in your array ' 20' , 'X20'
– alxwca