I am a real beginner to C, but I am learning!
I've stumbled upon this problem before and decided to ask what the reason for it is. And please explain your answers so I can learn.
I have made a program which allows you to input 5 characters and then show the characters you wrote and also revert them, example: "asdfg" - "gfdsa".
The weird thing is that a weird character is shown after the original characters that was inputted.
Here is the code:
char str[5];
char outcome[] = "OOOOO";
int i;
int u;
printf("Enter five characters
");
scanf("%s", str);
for(i = 4, u = 0; i >=0; u++, i--){
outcome[i] = str[u];
}
printf("
You wrote: %s. The outcome is: %s.", str , outcome);
return 0;
If I enter: "asdfg" it shows: "asdfg?", why is that?
Thank you for your time and please explain your answers :)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…