发布于 2012-09-21 21:12:12
4楼
以下是我用VC++6.0编译的读取文件数据的程序,如果要是放到wincc的c脚本里需要怎么改呢?谢谢
#include "stdio.h"
#include "string.h"
void main()
{
char b1[10000];
char c1[1200];
char ch,ch1,ch2,ch3,ch4;
int i,j,p,k;
int m=0,n=0;
FILE *fpin,*fpin3;
FILE *fpin2=fopen("C:\\Program Files\\Microsoft Visual Studio\\MyProjects\\ss\\zhongpin.emt\\in2.txt","r+");
if((fpin=fopen("C:\\Program Files\\Microsoft Visual Studio\\MyProjects\\ss\\zhongpin.emt\\in.snp","r"))==NULL)
{
printf("Cannot open this file!\n");
}
do
{fscanf(fpin,"%s",b1);
m++;
p=strcmp(b1,"!STOF:");}
while (p);
ch = fgetc(fpin);
ch1 = fgetc(fpin);
ch2 = fgetc(fpin);
ch3 = fgetc(fpin);
do
{fscanf(fpin,"%s",c1);
fprintf(fpin2,"%s ",c1);
n++;}
while (n!=120);//将in.snp里面的(!STOF:120)数组全部写到in2.txt文本中
if((fpin2=fopen("C:\\Program Files\\Microsoft Visual Studio\\MyProjects\\ss\\zhongpin.emt\\in2.txt","r"))==NULL)
{
printf("error on open this file\n");
}
if((fpin3=fopen("C:\\Program Files\\Microsoft Visual Studio\\MyProjects\\ss\\zhongpin.emt\\in3.txt","w"))==NULL)
{
printf("error on open this file\n");
}//打开两个文件
for(i=0;;i++)
{
ch4=fgetc(fpin2);
if((ch4=='.')(ch4=='-'))
{
for(j=0;;j++)
{
ch4=fgetc(fpin2);
if(ch4==' ')
{
break;
continue;
}
}
}//检查第一个字符是否为'.'或'-',如果是继续向下读知道读到空格号,则跳出子循环继续第一个循环。
else if(ch4==EOF)
{
fclose(fpin2);
fclose(fpin3);
}//检查文件是否到尾部,如果是的话则结束程序
else if(ch4>='1'&&ch4<='9')
{
for(k=0;;k++)
{
fputc(ch4,fpin3);
ch4=fgetc(fpin2);
if(ch4==' ')
{
fputc(' ',fpin3);
break;
continue;
}
}
}//如果第一个字符是数字则读出这行字符并保存到'in3.txt'文本里(将最终的数据写到in3.txt文本里)
}
fclose(fpin);
fclose(fpin2);
fclose(fpin3);
}
每一天都要当做生命的最后一天来度过!