C语言进行文件的存储,求修改
#include <stdio.h> #include <string>
#include <iostream>
using namespace std;
#define N 50
#define M 50
typedef unsigned char BYTE;
typedef unsigned int UINT;
typedef struct Modu
{
BYTE Type;
UINT ChildType;
BYTE Address;
BYTE ChildNum;
UINT Child[12];
BYTE XHDType[10];
};
/**将十六进制转换为十进制**/
long fun(char *s)
{
int i,t;
long sum=0;
for(i=0;s[i];i++)
{
if(s[i]<='9')
t=s[i]-'0';
else
t=s[i]-'a'+10;
sum=sum*16+t;
}
return sum;
}
main() /* 没有数据则返回0,有数据则返回1 */
{
FILE *fp;
int i,j,k,p=-1,m;
char ch[100],s[50],front[50],behind[50],element[M];
string s1,s2,s;
Modu MODU[N];
//modu *temp,*p=head;
if((fp=fopen("F:\\read\\Modu.txt","r"))==NULL)
{
printf("cannot open the file\n");
return(0);
}
do /*DO循环*/
{
strcpy(ch,""); /*置空数组*/
fgets(ch,100,fp); /*逐行读取文件信息*/
/**对文件里面的内容进行操作**/
j=strlen(ch);
if (strlen(ch)!=0) /*判断是否有效,长度不为0有效*/
{
for(i=0;i<j;i++)
{
if(ch[i]=='=')
{
for(k=0;k=i;k++)/*将每行"="前的内容分出来*/
{
front[k]=ch[k];
s1=front[k];
}
for(k=i+1;k<j;k++)/*将每行“=”后面的内容分出来*/
{
behind[k]=ch[k];
s2=behind[k];
}
for(k=11;k<i;k++)/*将在“=”前“."后的内容分出来*/
{
element[k-11]=ch[k];
s=element[k-11];
}
/**将文本中的内容存在结构体数组相应的位置**/
if(s=="Type")
{
p++;
MODU[p].Type=s2;
}
else if(s=="ChildType")
MODU[p].ChildType=s2;
else if(s=="Address")
{
m=fun(s2); /*将地址的十六进制转换成十进制*/
MODU[p].Address=m;
}
else if(s=="ChildNum")
MODU[p].ChildNum=s2;
else if(s=="Child[0]")
MODU[p].Child[0]=s2;
else if(s=="XHDType[0]")
MODU[p].XHDType[0]=s2;
else if(s=="Child[1]")
MODU[p].Child[1]=s2;
else if(s=="XHDType[1]")
MODU[p].XHDType[1]=s2;
else if(s=="Child[2]")
MODU[p].Child[2]=s2;
else if(s=="XHDType[2]")
MODU[p].XHDType[2]=s2;
else if(s=="Child[3]")
MODU[p].Child[3]=s2;
else
printf("error\n");
}
}
}
}while(strlen(ch)!=0); /*循环结束*/
fclose(fp); /*关闭文件指针*/
}
错误Settings\Administrator\桌面\MODU1\MODU.CPP(21) : warning C4091: 'typedef ' : ignored on left of 'struct Modu' when no variable is declared
C:\Documents and Settings\Administrator\桌面\MODU1\MODU.CPP(45) : error C2040: 's' : 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' differs in levels of indirection from 'char [50]'
C:\Documents and Settings\Administrator\桌面\MODU1\MODU.CPP(83) : error C2440: '=' : cannot convert from 'char' to 'char [50]'
There are no conversions to array types, although there are conversions to references or pointers to arrays
C:\Documents and Settings\Administrator\桌面\MODU1\MODU.CPP(90) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or th
ere is no acceptable conversion)
C:\Documents and Settings\Administrator\桌面\MODU1\MODU.CPP(93) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or th
ere is no acceptable conversion)
C:\Documents and Settings\Administrator\桌面\MODU1\MODU.CPP(96) : error C2664: 'fun' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
C:\Documents and Settings\Administrator\桌面\MODU1\MODU.CPP(100) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or t
here is no acceptable conversion)
C:\Documents and Settings\Administrator\桌面\MODU1\MODU.CPP(102) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or t
here is no acceptable conversion)
C:\Documents and Settings\Administrator\桌面\MODU1\MODU.CPP(104) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or t
here is no acceptable conversion)
C:\Documents and Settings\Administrator\桌面\MODU1\MODU.CPP(106) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or t
here is no acceptable conversion)
C:\Documents and Settings\Administrator\桌面\MODU1\MODU.CPP(108) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or t
here is no acceptable conversion)
C:\Documents and Settings\Administrator\桌面\MODU1\MODU.CPP(110) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or t
here is no acceptable conversion)
C:\Documents and Settings\Administrator\桌面\MODU1\MODU.CPP(112) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or t
here is no acceptable conversion)
C:\Documents and Settings\Administrator\桌面\MODU1\MODU.CPP(114) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or t
here is no acceptable conversion)
Error executing cl.exe.
MODU.exe - 13 error(s), 1 warning(s)
: