0
I compile the code below without errors. When I insert the word (or phrase desired) the printf
returns a random character like 0
�
a
etc. The program should read a word (or phrase) and the printf show the word (or phrase) that was written by the user.
I use gcc as a compiler. I’m compiling through the terminal at the moment. The distro I’m using is Manjaro 17.0.5 (I don’t know if this interferes with anything).
#include <stdio.h>
int main (void){
char example[20];
scanf("%*c", &example);
printf("example: %c\n", example);
return 0;
}
Why declare a vector and read only one character? Also I’ve never seen this
*
asterisk inscanf
, it seems strange to me– Jefferson Quesado
According to that reference, the
*
ignores the reading ofscanf
. So, even if you put character address in the read, the*
would read but would not store anywhere– Jefferson Quesado
You need to declare as String. A character vector is a string.
– Thiago Cunha
See more about reading with
scanf
here: https://answall.com/q/251918/64969– Jefferson Quesado