|
本帖最后由 time 于 2013-6-24 01:38 编辑
可以编译通过,但是运行有错误
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- long start_end(FILE * icid,long *sta[],long *end[])
- {
- long count=0;
- char dcn;
- while((dcn=getc(icid))!=NULL)
- {
- if(dcn=='\n')
- count++;
- }
- count++;
- rewind(icid);
- *sta=(long *)malloc(count*sizeof(long));
- *end=(long *)malloc(count*sizeof(long));
- count=0;
- while((dcn=getc(icid))!=NULL)
- {
- if(dcn=='(')
- *sta[count]=ftell(icid)+1;
- count++;
- }
- count=0;
- while((dcn=getc(icid))!=NULL)
- {
- if(dcn==')')
- *end[count]=ftell(icid)-1;
- count++;
- }
- return count;
- }
- void getidpw(char *id[],FILE *icid,long **sta,long **end,long count)
- {
- long ct;
- short len;
- for(ct=0;ct<=count;ct++)
- {
- fseek(icid,*sta[ct],SEEK_SET);
- len=*end[ct]-*sta[ct];
- fgets(id[ct],len,icid);
- strcpy(id[ct],"\n");
- }
- }
- void delcom(char fname[])
- {
- FILE *fp;
- char chg;
- fp=fopen(fname,"a");
- rewind(fp);
- while((chg=getc(fp))!=NULL)
- {
- if(chg==',')
- chg=':';
- putc(chg,fp);
- }
- puts("转换完成!");
- system("pause");
- }
- int main(void)
- {
- char filename[51];
- char **id;
- long *add1,*add2,count,ct;
- char dcn;
- FILE *icid;
- FILE *txt;
- system("title ICID to TXT");
- puts("请输入文件名");
- gets(filename);
- if((icid=fopen(filename,"r"))==NULL)
- {
- puts("打开icid文件失败");
- system("pause");
- exit(1);
- }
- strcpy(filename,".txt");
- if((txt=fopen(filename,"w"))==NULL)
- {
- puts("创建txt文件失败");
- system("pause");
- exit(2);
- }
- count=start_end(icid,&add1,&add2);
- id=(char **)malloc(count);
- getidpw(id,icid,&add1,&add2,count);
- for(ct=0;ct<=count;ct++)
- {
- fputs(id[ct],txt);
- }
- delcom(filename);
- return 0;
- }
复制代码 |
|