33,311
社区成员
发帖
与我相关
我的任务
分享
#include<stdio.h>
#include<stdlib.h>
int asciiToInteger(const char *string,int *integer )
{
char *p = (char *)string;
for( ; *p != '\0'; p++ )
{
if( *p < '0' || *p > '9' )
{
return 0;
}
}
*integer = atoi( string );
return 1;
}
void main()
{
int i,b;
char str[255];
scanf("%s",str);
b=asciiToInteger( str,&i );
printf("ת»»ºóµÄÊý×ÖΪ: %d\n",i);
printf("º¯Êý·µ»ØµÄBOOLֵΪ: %d\n\n",b);
}
#include<stdio.h>
#include<stdlib.h>
#define false 0//c99没有false
#define true 1//c99没有true
#define bool int//c99没有bool变量
bool asciiToInteger(const char *string,int *integer )
{
char* p ;//c99不支持将变量定义在for中。。。
for( p = (char *)string; *p != '\0'; p++ )
{
if( *p < '0' || *p > '9' )
{
return false;
}
}
*integer = atoi( string );
return true;
}
int main()
{
int i,b;
char str[255];
scanf("%s",str);
b=asciiToInteger( str,&i );
return 0;
}