im trying to reverse a string but im running into a problem where it says "subscripted value is neither array nor pointer nor vector" pointing to char holder = input[i]; can someone help explain that to me
myreverse(input, rev, len)
{
int i = 0;
int j= len -1;
char string[len];
while(i<j)
{
char holder = input[i];
string[i]= string[j];
string[j] = holder;
i++;
j--;
}
}
int main(int argc, char* argv[]) {
if (argc < 2) {
printf("Usage: %s <word to reverse>\n", argv[0]);
exit(1);
}
char* input = argv[1];
int len = strlen(input);
char rev[len + 1]; // Adding one for the null terminator
myreverse(input, rev, len);
printf("Rev string is %s\n", rev);
}
myreverse()function, so the return type and the argument types are all assumed to beint, and you can't subscriptint. It should bevoid myreverse(char *input, char *rev, int len)or thereabouts. You don't use therevparameter in the code; that's bad too. - Jonathan Lefflerintin combination with VLAs (char string[len]), which are a C99 feature. - melpomeneintfrom the language. - melpomene