- 论坛徽章:
- 0
|
(2)
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
long fun(char *in) {
char out[257];
memset(out, '\0', sizeof(out));
sprintf(out, "%0*ld", strlen(in), atol(in));
if(strcmp(in, out) != 0) {
// printf("**********error************\n");
return -1;
} else {
return atol(in);
}
}
main()
{
printf("$$$$$$$$$$$ %ld $$$$$$$$$$$$\n", fun("-12345"));
printf("$$$$$$$$$$$ %ld $$$$$$$$$$$$\n", fun("0000"));
printf("$$$$$$$$$$$ %ld $$$$$$$$$$$$\n", fun("000125"));
printf("$$$$$$$$$$$ %ld $$$$$$$$$$$$\n", fun("sfdg12"));
printf("$$$$$$$$$$$ %ld $$$$$$$$$$$$\n", fun("1234gh"));
printf("$$$$$$$$$$$ %ld $$$$$$$$$$$$\n", fun("654"));
}
测试结果:
$$$$$$$$$$$ -12345 $$$$$$$$$$$$
$$$$$$$$$$$ 0 $$$$$$$$$$$$
$$$$$$$$$$$ 125 $$$$$$$$$$$$
$$$$$$$$$$$ -1 $$$$$$$$$$$$
$$$$$$$$$$$ -1 $$$$$$$$$$$$
$$$$$$$$$$$ 654 $$$$$$$$$$$$ |
|