#include
#include
int
main (int argc, char *argv[])
{
FILE *fp;
FILE *file;
char temp[1024];
char tmp[1024];
char buffer[1024];
char *delim=" ";
char *p[1024];
int i;
int n;
fpos_t pos;
if (fp = fopen ("statusbar.c", "r"))
{
while (feof (fp) == 0)
{
memset (temp, 0, sizeof (temp));
fgets (temp, sizeof (temp), fp);
if (strstr (temp, "str3") != NULL)
{
fgetpos(fp, &pos);
printf ("postition =======================================================================%d\n", pos);
if (file = fopen ("/root/a.xls", "a+r")){
p[0] = strtok(temp, delim);
printf ("%s\n", p[0]);
sprintf (tmp, "%s\t", p[0]);
printf ("%s\n", tmp);
fwrite (tmp, sizeof (char), strlen(tmp), file);
n = 1;
while((p[n]=strtok(NULL,delim))){
sprintf (tmp, "%s\t", p[n]);
printf ("%s\n", p[n]);
fwrite (tmp, sizeof (char), strlen(tmp), file);
n ++;
}
fwrite ("\n", sizeof (char), strlen("\n"), file);
fclose(file);
}
for (i = 0; i <= 10; i++)
{
memset (buffer, 0, sizeof (buffer));
fgets (buffer, sizeof (buffer), fp);
if (strstr (buffer, "^sum") != NULL)
{
if (file = fopen ("/root/a.xls", "a+r")){
p[0] = strtok(buffer, delim);
printf ("%s\n", p[0]);
sprintf (tmp, "%s\t", p[0]);
printf ("%s\n", tmp);
fwrite (tmp, sizeof (char), strlen(tmp), file);
n = 1;
while((p[n]=strtok(NULL,delim))){
sprintf (tmp, "%s\t", p[n]);
printf ("%s\n", p[n]);
fwrite (tmp, sizeof (char), strlen(tmp), file);
n ++;
}
fwrite ("\n", sizeof (char), strlen("\n"), file);
fclose(file);
}
printf ("%s\n", buffer);
}
}
printf ("End =========================================================================\n");
fsetpos (fp, &pos);
}
}
fclose (fp);
}
else
{
printf ("Open file error\n");
}
return 0;
}
daiwanbing888 于 2010-07-22 09:44:31发表:
bucuo
windycool 于 2010-03-22 08:07:08发表:
[i=s] 本帖最后由 windycool 于 2010-3-22 08:08 编辑 [/i]
附件没有错的,代码和linux 下的有点不一样,我主要是看看能不能在windows下应用,就弄了个小界面,另外这个程序还有点不完善。
while((p[n]=strtok(NULL,delim))) 这个不是个死循环,当在余下的字符串里找不到以delim为分隔的子字符串就跳出循环了。
zj_yqj 于 2010-03-18 10:57:45发表:
[i=s] 本帖最后由 zj_yqj 于 2010-3-18 11:27 编辑 [/i]
好,能把自己的学习经验贡献出来,有GNU精神。
但是附件下来看看,怎么是用VC写的代码??
楼主是不是发错附件了
另while((p[n]=strtok(NULL,delim))){
好象是进入一个死循环,没有退出点。
Harlech 于 2010-03-16 20:47:50发表:
强人
xzj4167 于 2010-03-16 17:14:14发表:
看不懂 虽然学了点C语言