string - Errors using pointers with Function in C -
first of apologize, simple question i'm not versed in coding. code, need use pointer syntax , define own function reverse string. i'm not allowed use strlen() in situation. i've tried playing around pointers, following errors:
incompatible type when assigning type char[15] type char (i have write in pico, i'm not sure line number refers to. appears somewhere around point call strcmp() function
assignment makes integer pointer without cast (this 1 appears when define s pointer in function or around there)
any , help/troubleshooting ideas appreciated. i'm using gcc compiler, if matters
#include<stdio.h> #include<string.h> char revcheck(char string[15]); int main(void) { char string[15]; printf("enter string: \n"); scanf(" %s", string); if (strcmp(string, "engr-awesome")) { printf("that's right!"); } else { string = revcheck(string); } return 0; } char revcheck(char string[15]) { char letter, *end, *s; end = strchr(string, '\0'); s = string; while (end > s) letter = &end; *end = *s; *s = letter; end--; s++; return 0; }
your revcheck() returns char. trying assign char[].
you should have revcheck() return char*:
char* revcheck(char string[15]);
Comments
Post a Comment