不好意思,我不太理解您的算法,以下是我写的,希望对您有帮助:
程序代码:
#include <stdio.h>
#include <string.h>
#define MAX_LENGTH 80
int main(int argc, char const *argv[]) {
int i, len;
char src[MAX_LENGTH];
char dst[MAX_LENGTH];
printf("Enter your sentence (length < %d).\n", MAX_LENGTH);
scanf("%s\n", src);
len = strlen(src);
for (i = 0; i < len; ++i) {
dst[i] = src[len-1 - i];
/* e d c b a '\0'
* 4 3 2 1 0 -------- in src
* 0 1 2 3 4 -------- in dst
* ^^^^^^^^^ -------- sum = len-1
*/
}
dst[i] = '\0';
printf("%s\n", dst);
return 0;
}