将writelogs的参数(logname除外)连接起来,写成一条日志,我的程序写错了,帮帮忙看下

jourmen 2003-08-27 03:33:31
/*
实现功能:将writelogs的参数(logname除外)连接起来,写成一条日志

*/

# include <stdio.h>
# include <string.h>

int writelogs(char logname[],int errcode,int errrate,int suberrcode,unsigned char *msg);
int main(void)
{
writelogs('a',0x111,0x1,0x1111,'hello,it is a test1');
writelogs('b',0x222,0x1,0x3333,'hello,it is a test2');

return 0;
}

int writelogs(char logname[],int errcode,int errrate,int suberrcode,unsigned char *msg)
{
FILE *fp;
unsigned char temp1,temp2,temp3,temp4;
temp1=strcat(errcode,errrate);
temp2=strcat(temp1,suberrcode);
temp3=strcat(temp2," ");
temp4=strcat(temp2,msg);

/******mkfile-start*******/


if((fp=fopen("logname[]","a"))==NULL)
{
printf("error");
exit(0);
}
/******mkfile-over*******/

/******writelog-start*******/

gets(temp4);
strcat(temp4,"\n");/*add a newline*/
fputs(temp4,fp);


/******writelog-over*******/
fclose(fp);
return 0;
}


==========
我急用,请帮帮忙:)
...全文
66 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
njtu 2003-08-27
  • 打赏
  • 举报
回复
//编译通过,in dev c++

# include <stdio.h>
# include <string.h>
int writelogs(char* logname,char* errcode,char* errrate,char* suberrcode,char* msg);

int main(void)
{
writelogs("a","0x111","0x1","0x1111","hello,it is a test1");
writelogs("b","0x222","0x1","0x3333","hello,it is a test2");

return 0;
}


int writelogs(char* logname,char* errcode,char* errrate,char* suberrcode,char* msg)
{
FILE *fp;
char buf[1000];
buf[0] = '\0';
strcat(buf,errcode);
strcat(buf,errrate);
strcat(buf,suberrcode);
strcat(buf," ");
strcat(buf,msg);

/******mkfile-start*******/

if((fp=fopen(logname,"a"))==NULL)
{
printf("error");
return 0;
}
fwrite(buf,sizeof(buf),1,fp);
fclose(fp);
return 0;
}
jourmen 2003-08-27
  • 打赏
  • 举报
回复
生成的日志记录要是ASCII的,不可以是二进制流的
我急用,日记名是通过logname生成的。
而且日记要每行一条

怎么坐呢,我好久没有用c了,:(
jourmen 2003-08-27
  • 打赏
  • 举报
回复
还是不可以,调试通不过
大家在给我看看:
# include <stdio.h>
# include <string.h>
int writelogs(char logname[],char errcode,char errrate,char suberrcode,char msg);

int main(void)
{
writelogs("a","0x111","0x1","0x1111","hello,it is a test1");
writelogs("b","0x222","0x1","0x3333","hello,it is a test2");

return 0;
}


int writelogs(char logname[],char errcode,char errrate,char suberrcode,char msg)
{
FILE *fp;
char buf[1000];
buf[0] = '\0';
strcat(buf,errcode);
strcat(buf,errrate);
strcat(buf,suberrcode);
strcat(buf," ");
strcat(buf,msg);

/******mkfile-start*******/

if((fp=fopen(logname,"a"))==NULL)
{
printf("error");
exit(0);
}
fwrite(buf,sizeof(buf),1,fp);
fclose(fp);
return 0;
}
njtu 2003-08-27
  • 打赏
  • 举报
回复
int writelogs(char logname[],int errcode,int errrate,int suberrcode,unsigned char *msg)
{
FILE *fp;
char buf[100];
buf[0] = '\0';
//分隔符我没加,自己改
strcat(buf,itoa(errcode));
strcat(buf,itoa(errrate));
strcat(buf,itoa(suberrcode));
strcat(buf,msg);

/******mkfile-start*******/

if((fp=fopen(logname,"a"))==NULL)
{
printf("error");
exit(0);
}
fwrite(buf,sizeof(buf),fp);
fclose(fp);
}


看你想怎么用,也可以使用fprintf(),也许更方便
jourmen 2003-08-27
  • 打赏
  • 举报
回复
可以详细的帮我改下吗?
谢谢!
bigdoors 2003-08-27
  • 打赏
  • 举报
回复
writelogs('a',0x111,0x1,0x1111,'hello,it is a test1');
用双引号表示字符串,但引号是表示字符

writelogs的参数int errcode,int errrate,int suberrcode也要转换成字符串

70,020

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧