I am trying to print array of characters in C, but the array is not printing if any blank space occurs. This is my code:
int main() {
char str[100];
int len = 0;
printf("Enter the string");
scanf("%s", str);
len = strlen(str);
int i = 0;
for (i = 0; i < len; i++) {
printf("%s", str[i]);
}
getch();
}
Input: Bangalore is in India
Output: Bangalore
Any suggestions?
%sis the format specifier for a string. You are trying to print one character at a time (str[i]). So you should either, just once, doprintf("%s\n", str);or, in your loop, doprintf("%c", str[i]);and follow that withprintf("\n");(newline string) orputch('\n');(newline char).