I'm playing around with user input and printing strings. Whenever I run the code, the last string that I am trying to print is being glitched and doesn't print out correctly.
my code is:
#include <stdio.h>
int main() {
char inputRoses[] = "";
char inputViolets[] = "";
char inputAnd[] = "";
char roses[] = "Roses are: ";
char violets[] = "Violets are: ";
char and[] = "and: ";
printf("\n%s", roses);
scanf("%s", inputRoses);
printf("\n%s", violets);
scanf("%s", inputViolets);
printf("\n%s", and);
scanf("%s", inputAnd);
return 0;
}
Got this in the console:
Roses are: red
Violets are: blue
ue
I also tried this:
#include <stdio.h>
int main() {
char inputRoses[] = "";
char inputViolets[] = "";
char roses[] = "Roses are: ";
char violets[] = "Violets are: ";
printf("\n%s", roses);
scanf("%s", inputRoses);
printf("\n%s", violets);
scanf("%s", inputViolets);
return 0;
}
But got this in the console:
Roses are: red
ed
inputRosescan store only an empty string as strings in C require a null terminating character.