程序代码:
#include <stdio.h> #include <malloc.h> #include <string.h> int main(int argc, char** argv) { char a[] = " I AM STEDENT "; int i = 0; int j = 0; int nSum = 0; char** pp = (char**)malloc(sizeof(char*)*strlen(a)); memset(pp, '\0', sizeof(char*)*strlen(a)); for(i = 0; i < strlen(a); i++) { pp[i] = (char*)malloc(sizeof(char)*strlen(a)); memset(pp[i], '\0', sizeof(char)*strlen(a)); } char* pTmp = a; while(*pTmp) { if(*pTmp ==' ') { pp[j++][i] = ' '; nSum++; i = 0; } else { pp[j][i++] = *pTmp; } pTmp++; } for(i = nSum; i >= 0; i--) { printf("%s ", pp[i]); } printf("\n"); for(i = 0; i < sizeof(char)*strlen(a); i++) { free(pp[i]); } free(pp); return 0; }