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

jourmen IBM 架构师  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;
}


==========
我急用,请帮帮忙:)
...全文
10 点赞 收藏 6
写回复
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也要转换成字符串
回复
发动态
发帖子
C语言
创建于2007-09-28

6.3w+

社区成员

C语言相关问题讨论
申请成为版主
社区公告
暂无公告