C语言函数出错 cannot convert from 'char' to 'char *'
这是函数,求大神看看哪里错了,小弟感谢万分!!#include"stdio.h"#include"stdlib.h"#include"string.h"typedefst...
这是函数 ,求大神看看哪里错了,小弟感谢万分!!
#include"stdio.h"
#include"stdlib.h"
#include"string.h"
typedef struct work
{
char num[10];
char name[10];
char sex[10];
char age[10];
}STU;
int main()
{
STU stu={"1001","12","45","19"};
STU stu1,stu2;
int x;char ch1[10];char *ch=ch1;
FILE *f=fopen("D:\letter.txt","w+");
fwrite(&stu,sizeof(struct work),1,f);
rewind(f);
fread(&stu1,sizeof(struct work),1,f);
x=atoi(stu1.num);
ch=(char)(++x);
strcpy(stu1.num,ch1);
fwrite(&stu1,sizeof(struct work),1,f);
printf("%s\t%s\t%s\t%s\t",stu1.num,stu1.name,stu1.sex,stu1.age);
return 0;
} 展开
#include"stdio.h"
#include"stdlib.h"
#include"string.h"
typedef struct work
{
char num[10];
char name[10];
char sex[10];
char age[10];
}STU;
int main()
{
STU stu={"1001","12","45","19"};
STU stu1,stu2;
int x;char ch1[10];char *ch=ch1;
FILE *f=fopen("D:\letter.txt","w+");
fwrite(&stu,sizeof(struct work),1,f);
rewind(f);
fread(&stu1,sizeof(struct work),1,f);
x=atoi(stu1.num);
ch=(char)(++x);
strcpy(stu1.num,ch1);
fwrite(&stu1,sizeof(struct work),1,f);
printf("%s\t%s\t%s\t%s\t",stu1.num,stu1.name,stu1.sex,stu1.age);
return 0;
} 展开
展开全部
#include"stdio.h"
#include"stdlib.h"
#include"string.h"
typedef struct work
{
char num[10];
char name[10];
char sex[10];
char age[10];
}STU;
int main()
{
STU stu={"1001","12","45","19"};
STU stu1,stu2;
int x;
char ch1[10];
//原代码char *ch=ch1;
//原代码FILE *f=fopen("D:\letter.txt","w+");
FILE *f=fopen("D:\\letter.txt","w+"); //要加双斜杠"\\"
if(f==NULL)
{
printf("\n打开文件出错.\n");
exit(1);
}
fwrite(&stu,sizeof(struct work),1,f);
rewind(f); //将文件指针重新指向开头
fread(&stu1,sizeof(struct work),1,f);
x=atoi(stu1.num); //字符串转换为数字
//原代码ch=(char)(++x);
x++; //数字由1001变为1002
itoa(x,ch1, 10); //数字转换为字符串
strcpy(stu1.num,ch1);
rewind(f); //将文件指针重新指向开头
fwrite(&stu1,sizeof(struct work),1,f);
printf("%s\t%s\t%s\t%s\t",stu1.num,stu1.name,stu1.sex,stu1.age);
fclose(f); //最后要关闭文件
return 0;
}
追问
哦 原来将数字转换成字符串不是用强制类型转换函数吗?
万分感谢
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询