linux下如何编写函数

来源:百度知道 编辑:UC知道 时间:2024/06/16 18:56:12
在linux目录下有这样一个文档:
12:zhipeng:yang:it
abc:zhou:shan:Services
124:wen:zhang:sales
125:yang:yang:it
128:peng:wu:it
321:zhen:chen:sales
def:lai:liu:it
324:quan:song:sales
345:ling:wang:sales
456:hao:wang:Services
hao:yu:chen:sales
465:yu:zhou:Claims
478:wang:kai:It
789:cao:cao:it
1、 编写一个判断变量是否是数字的函数;
2、 然后以冒号“:”为分隔符,对上述文档中每行的第一字段进行数字函数判断;
请教各位高手帮小弟解答一下,谢谢,急!

leave@LEAVE:~/test$ more 1.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
FILE * fp;

if (NULL == (fp=fopen("./hhh.txt", "rb")))
{
return 0;
}

while(!feof(fp))
{
char linebuf[256] = "";
char * pstr;
int ret = 0;

if (NULL == (pstr=fgets(linebuf, sizeof(linebuf), fp)))
break;

pstr += strspn(pstr, "\t\x20\n\r"); // jump over space
if ('\0' == *pstr ) // jump over blank line
continue;

if('0' <= *pstr && '9' >= *pstr)
{
printf("%s\n", strtok(pstr,":") );
}
}
return 0;
}
leave@LEAVE:~/test$ gcc -o 1 1.c
leave@LEAVE:~/test$ ./1
12
124
125
128
321
324
345
456
465
478