69,372
社区成员
发帖
与我相关
我的任务
分享
root@~ #cat isdigit.c
#include <stdio.h>
#include <stdbool.h>
int main (void) {
char str[81];
bool isdigit (char str[]);
scanf ("%s",str);
if(isdigit(str)) {
printf ("yes\n");
}else{
printf ("No!\n");
}
return 0;
}
bool isdigit (char str[]) {
int i=0;
bool isIntStr;
while(str[i]!='\0') {
if(str[i]>='0'&&str[i]<='9') {
i++;
}else{
return isIntStr=false;
}
}
return isIntStr=true;
}
root@~ #
string numstr = "5665";
int len = strspn(numstr.c_str(),"1234567890");
int len2 = numstr.size();
if (len == len2)
//d.txt为下面一行内容:( 去掉前面的// )
//01.2,3.45;5.6789 -0.12345678901234 abc 1234567890.123456789123456789 1e300 0
#include <stdio.h>
int n,r;
double d;
FILE *f;
void main() {
f=fopen("d.txt","r");
n=0;
while (1) {
r=fscanf(f,"%lf",&d);
if (1==r) {
n++;
printf("[%d]==%.15lg\n",n,d);//可以试试注释掉这句以后的速度
} else if (0==r) {
fgetc(f);
} else break;
}
fclose(f);
}
//实际运行输出:( 去掉前面的// )
//[1]==1.2
//[2]==3.45
//[3]==5.6789
//[4]==-0.12345678901234
//[5]==1234567890.12346
//[6]==1e+300
//[7]==0
#include <stdio.h>
#include <conio.h>
int i = 0;
char c;
void main() {
while (1) {
printf("\nPlease input a number:");
rewind(stdin);
if (2==scanf("%d%c",&i,&c)) {
if ('\n'==c) {
printf("\nThe number is %d.\n", i);
break;
}
}
}
printf("Press any key to end ...");
getch();
}
//
//Please input a number:12a
//
//Please input a number:a
//
//Please input a number:12
//
//The number is 12.
//Press any key to end ...