C语言字符转换为数字的问题

ha_y 2003-08-21 01:10:29
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
using namespace std;
main()
{
char *pLogPath;

int iFileLoop = 1;
while ( iFileLoop < 10 )
{
char cFileLoop = (char) iFileLoop;
strcat( pLogPath, "(" );
strcat( pLogPath, cFileLoop );
strcat( pLogPath, ")" );
printf("%s", pLogPath);
}
}
出错cFileLoop 必须是const char才能用strcat(),但是怎样才能达到同样的效果呢?
...全文
82 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
leialen 2003-08-21
  • 打赏
  • 举报
回复
错了,sorry.我瞎说,再也不敢
leialen 2003-08-21
  • 打赏
  • 举报
回复
分配空间,达到同样效果
EmailTan 2003-08-21
  • 打赏
  • 举报
回复
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void main()
{
char pLogPath[100]={0};
// char *pLogPath;
strcpy( pLogPath, "(" );
int iFileLoop = 1;
while ( iFileLoop < 10 )
{
char cFileLoop[1];
_itoa(iFileLoop,cFileLoop,10);

strcat( pLogPath, cFileLoop);

iFileLoop++ ;
}
strcat( pLogPath, ")" );

printf("%s", pLogPath);
}
EmailTan 2003-08-21
  • 打赏
  • 举报
回复
void main()
{
char pLogPath[100]={0};
// char *pLogPath;
strcpy( pLogPath, "(" );
int iFileLoop = 1;
while ( iFileLoop < 10 )
{
char cFileLoop[1];
cFileLoop[0] = (char) iFileLoop;

strcat( pLogPath, (cFileLoop) );

iFileLoop++ ;
}
strcat( pLogPath, ")" );

printf("%s", pLogPath);
}
blue_coco 2003-08-21
  • 打赏
  • 举报
回复
未分配空间

char *pLogPath;
改为
char pLogPath[100];




EmailTan 2003-08-21
  • 打赏
  • 举报
回复
进行强制转换

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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