So I've been reading and practicing C for a few months now on and off, and I finally decided to start hacking away at some code. So I googled for some simple programs to try writing and the first one was a program to reverse whatever the user input is. Now I don't want any answers but if you could maybe clue me in if I'm using any functions wrong or something.
the code is: (ignore the printf of the strlen its for debugging)
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]) {
char command[100];
printf("please enter string: ");
fgets(command, 100, stdin);
//printf("%d", strlen(command));
int ha = strlen(command);
while(1){
if(!strcmp(command,"quit")) {
for(int i = 0; i < ha; i++) {
int str = strlen(command) - i;
puts(command[str]);
}
} else {
exit(0);
}
printf("please enter string: ");
fgets(command, 100, stdin);
}
return 0;
}
It compiles with no warnings or errors but when ran after entering some input it gives me a segmentation fault. any help is very much appreciated!