将student a am I转换为 I am a student
#include <stdio.h> #include <string.h> void reverse( char *start,char *end ) { char* left = start; char* right = end; char temp; while( left < right ) { temp = *left; *left = *right; *right = temp; left++; right--; } } void check( char *p ) { while( *p != ‘\0‘) { char *pst = p; while( *p != ‘\0‘ && *p != ‘ ‘ ) { p++; } reverse( pst,p-1 ); if(*p!=‘\0‘) p++; } } int main() { char p[30] = "student a am i"; int len = strlen(p); printf("翻转后的字符串是:"); reverse(p,p+len-1); check(p); printf("%s\n",p); return 0; }
时间: 2024-08-02 11:02:16