C: problem z char *
/*
* code.c
*
* TASK
* Reverse a string by reversing pointers. Function should use return
* type char* and use a char* parameter as input.
*/
#include <stdio.h>
#include <string.h>
#define STRMAX 51
char* reverse(char* sPhrase[]);
int main() {
char sPhrase[STRMAX];
char sReverse[STRMAX];
printf("Enter string (max. 50 chars): ");
gets(sPhrase);
sReverse = reverse(sPhrase);
return 0;
}
char* reverse(char* sPhrase[]) {
char* sOutput[STRMAX];
int iCnt = 0, iCntRev;
for (iCntRev = strlen(*sPhrase)-2; iCntRev >= 0; iCntRev--) {
sOutput[iCnt] = sPhrase[iCntRev];
iCnt++;
}
*sOutput[iCnt] = '\0'; // Don't forget to close the string
return sOutput;
}
Ten kod ma pewne dziwactwa:
sReverse = reverse(sPhrase);
return sOutput;
Co oznaczają te ostrzeżenia? Jak mogę załatać błędy? Funkcja powinna zachować char * jako typ powrotu i jako parametr, ponieważ robię ten mały program jako część szkolenia C.