Novice programmer learning C, I'm encountering this 'segmentation fault (core dumped)' error while trying to run a for-loop with strcmp. I have seen questions on similar issues with strcmp, but they don't seem to address my problem. Here's the program I've written.
#include<stdio.h>
#include<string.h>
int main() {
char ftpstring[15];
printf("\nEnter valid ftp command > ");
fgets(ftpstring,15,stdin);
const char* ftp[] = { "ascii", "recv", "send", "rmdir", "mkdir" , "pwd", "ls", "cd", "status", "quit" };
for ( int i = 0; i <= 10; i++ ) {
int comparison;
comparison = strcmp(ftpstring, ftp[i]);
if (comparison == 0 ) {
printf("%s is a valid ftp command.", ftpstring);
break;
}
if(i == 10) {
printf("%s is NOT a valid ftp command.", ftpstring);
}
}
}
As you can see, this program tries to read user input to determine if it matches one of the predefined valid ftp commands, then return whether or not it does.