返回:贺老师课程教学链接
#include <stdio.h> int main( ) { char b[]="ADCEBADEFG"; char *chp=&b[9]; while(--chp>&b[2]) putchar(*chp); putchar('\n'); return 0; }
#include <stdio.h> int main( ) { char s[]="ABCD",*p; for(p=s+1; p<s+4; p++) printf("%s\n",p); return 0; }
#include <stdio.h> int main( ) { char ch[]= {"12yue25ri"}; int i,s=0; for(i=0; ch[i]>='0' && ch[i]<='9'; i++) s=10*s+ch[i]-'0'; printf("%d\n",s); return 0; }
#include <stdio.h> int main( ) { char *s="12134211"; int v[4]= {0,0,0,0} ; int k,i; for(k=0; s[k]; k++) { switch(s[k]) { case '1': i=0;break; case '2': i=1;break; case '3': i=2;break; case '4': i=3;break; } v[i]++; } for(k=0; k<4; k++) printf("%d",v[k]); return 0; }
#include <stdio.h> int main( ) { int i=0; char a[ ]="abm", b[ ]="aqid", c[10]; while (a[i]!='\0' && b[i]!='\0') { if (a[i]>=b[i]) c[i]=a[i]-32 ; else c[i]=b[i]-32 ; i++; } c[i]='\0'; puts(c); return 0; }
#include <stdio.h> int main( ) { char s[80]; int i=0; gets(s); while (s[i]!='\0') { if (s[i]<='z' && s[i]>='a') s[i]='z'+'a'-s[i] ; i++; } puts(s); return 0; }
#include <stdio.h> int main( ) { int i,s; char s1[100],s2[100]; printf("input string1:\n"); gets(s1); printf("input string2:\n"); gets(s2); i=0; while ((s1[i]==s2[i])&&(s1[i]!='\0')) i++; if ((s1[i]=='\0')&&(s2[i]=='\0')) s=0; else s=s1[i]-s2[i]; printf("%d\n",s); return 0; }
#include <stdio.h> int main( ) { int n=0; char str[80]="Beijing-China 2008"; printf("%s\n",str); while(str[n]!='\0') str[n++]=(str[n]>='a'&&str[n]<='z')?(str[n]-'a'+'A'):str[n]; printf("%s\n",str); return 0; }
#include <stdio.h> #include<string.h> char cchar(char ch) { if (ch>='A'&&ch<='Z') ch=ch-'A'+'a'; return ch; } int main() { char s[]="ABC+abc=defDEF",*p=s; while(*p) { *p=cchar(*p); p++; } printf("%s\n",s); return 0; }
#include <stdio.h> #include<string.h> void fun(char *p, int n) { char *i,*j,t; for (i=p,j=p+n-1; i<j; i++,j--) { t=*i; *i=*j; *j=t; } } int main() { char s[]="1234567890"; fun(s,strlen(s)); puts(s); return 0; }
#include <stdio.h> #include<string.h> void del (char *s,char c ) { int i,j; for (i=j=0; s[i]!='\0'; i++) if (s[i]!=c) s[j++]=s[i]; s[j]='\0'; } int main() { char s[]="the c language"; del(s,'a'); puts(s); return 0; }
#include <stdio.h> #include<string.h> # include "ctype.h" void space(char *str) { int i ,t ; char ts[81]; for(i=0,t=0 ; str[i]!='\0' ; i+=2) if(!isspace(*(str+i))&&(*(str+i)!='a')) ts[t++]=toupper(str[i]) ; ts[t]='\0' ; strcpy(str ,ts) ; } int main( ) { char s[81]= {"abcdefg"} ; space(s); puts(s); return 0; }