反序字符串,只需要将首尾字符依次调换即可。include <stdio.h>#include <string.h>// 反序字符串x并返回char* reverse(char *x){ int len = strlen(x); int i, n = len / 2; char tem; for (i = 0; i <= n; i++) { tem = x[i]; x[i] = x[len...
printf("请输入一个字符串:"); gets(ch); inverse(ch); printf("逆序存储后的字符串为:"); puts(ch);}
include <string.h> void main(){ int i, len;char temp;char buf[512] = { 0 };scanf("%s", buf);len = strlen(buf);for (i = 0; i < len/2; i++){ temp = buf[i];buf[i] = buf[len - 1 - i];buf[len - 1 - i] = temp;} printf("%s", buf);} ...
int main(void){ int i;int ch[128];for (i = 0; (ch[i] = getchar()) != '\n'; i++);printf("\n");for (; i >= 0; i--)printf("%c", ch[i]);getch();return 0;} 在 TC 上测试通过 用链表实现,动态存储,字符串长度无限制 include<alloc.h> include<conio.h>...
int main(int argc,char *argv[]){ char s[81],ln;while(1){ printf("Enter a string...\n");if(scanf("%80s",s)!=1)break;for(ln=0;s[ln];ln++);//求输入字符串长度 putchar('\n');for(ln--;ln>=0;ln--)if(s[ln]>='a' && s[ln]<='z' || s[ln]>='A' ...
以一个8为字符串为例:代码如下 include<stdio.h> int main(){ int i,j;char ch1[8],ch2[8];for(i=0;i<8;i++){ printf("请输入第%d个字符",i);scanf("%c",&ch1[i]);fflush(stdin);} for(j=0;j<8;j++){ ch2[j]=ch1[7-j];printf("%c",ch2[j]);} } ...
include <stdio.h> int main(){ char s1[20], s2[20];scanf("%s", s1);int l=0,i=0;while(s1[l] !='\0') l++;for(i=0;i<l;i++){ s2[l-1-i]=s1[i];} s2[l]='\0';printf("%s", s2);return 0;}
int main(){ char s[3000],c[1000][20]={0};//c[j]来储存单词,k是单词中的字母 int i,j=0,k=0;gets(s);for(i=0; i<strlen(s); i++){ if(s[i]==' '){ j++; //遇空格换下一个单词,k归零 k=0;continue;} c[j][k]=s[i];k++;} for(i=j; i>=0; i-...
include <stdio.h> include <string.h> void inv(char* a){ int len = strlen(a), i;char t;for(i=0;i<len/2;i++){ t = a[i];a[i] = a[len-1-i];a[len-1-i] = t;} } int main(){ char a[255];gets(a);inv(a);puts(a);return 0;} ...