I am currently learning C, and I want to create a function that reverses an input. Here is the piece of code I wrote:
#include <stdio.h>
int main(int argc, char** argv) {
char input[100];
while(1) {
fgets(input, 100, stdin);
for(int i = 99; i > -1; i--) {
printf("%c", input[i]);
}
printf("\n");
}
}
The output of this is correct, but it also prints some garbage in between and I don't understand why. Can someone explain this to me?
This is the output: