#include <stdio.h>int main(){ char s1[100], s2[100]; int i,j; gets(s1); for(i = j = 0; s1[i]; i ++) if(s1[i]>="0"&&s1[i]<="9") s2[j++] = s1[i]; s2[j] = 0; puts(s2); return 0;}指標方式類似.#include <stdio.h>int main(){ char s1[100], s2[100]; char *p1=s1, *p2=s2; gets(p1); while(*p1) { if(*p1>="0"&&*p1<="9") *p2++ = *p1; p1++; } *p2 = 0; puts(s2); return 0;}
#include <stdio.h>int main(){ char s1[100], s2[100]; int i,j; gets(s1); for(i = j = 0; s1[i]; i ++) if(s1[i]>="0"&&s1[i]<="9") s2[j++] = s1[i]; s2[j] = 0; puts(s2); return 0;}指標方式類似.#include <stdio.h>int main(){ char s1[100], s2[100]; char *p1=s1, *p2=s2; gets(p1); while(*p1) { if(*p1>="0"&&*p1<="9") *p2++ = *p1; p1++; } *p2 = 0; puts(s2); return 0;}