I wrote and compiled this program in codeblocks:
#include <stdio.h>
#include <stdlib.h>
int main() {
char myChar[155];
scanf("%s", myChar);
printf("%s\n", myChar);
return 0;
}
I have tried many things but for some reason when you input a string with more than one word, the console only outputs the first word. Is it the fault of the compiler or am I doing something wrong here?
%sactually does. cplusplus.com/reference/cstdio/scanfscanfwith%sworks. It only stores one [whitespace separated] word. To input a whole line string such as:Mauser Maschine[scanfwill only getMauser], usefgets[and strip the newline]. Then, you'll have the full string [with the spaces]. In other words, try:fgets(myChar,sizeof(myChar),stdin); myChar[strcspn(myChar,"\n")] = 0;fpart ofscanfis there for a reason.