>>657 引き数として与えられた文字列の数字のみを抜き出すプログラム。多分これで完璧?
#include <stdlib.h>
int main(int argc, char **argv){
char *cReadSpell, *cWriteSpell;
int nSpellLen, counter, nAsciiCode, nWriteNumber;
if(argc != 2){
printf("引き数不正\n");
return -1;
}
nSpellLen = strlen(*(argv+1)) + 1;
cReadSpell = (char*)malloc(nSpellLen);
strcpy(cReadSpell, (const char*)(*(argv+1)));
cWriteSpell = (char*)malloc(nSpellLen);
strcpy(cWriteSpell, "\0");
for(counter = 0; cReadSpell[counter] != '\0'; counter++){
nAsciiCode = *(cReadSpell+counter);
nSpellLen = strlen(cWriteSpell);
if(nAsciiCode >= 48 && nAsciiCode<= 57){
cWriteSpell[nSpellLen] = *(cReadSpell+counter);
}
}
strcat(cWriteSpell, "\0");
nSpellLen = atoi(cWriteSpell);
printf("%d\n", nSpellLen);
free(cReadSpell);
free(cWriteSpell);
return 0;
}