gpt4 book ai didi

C代码int到字符串不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 03:48:06 25 4
gpt4 key购买 nike

这是我使用 itoa() 函数的代码,似乎无法正常工作。让我说清楚,我正在研究 C。

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

void main()
{
int i,j;
for(i = 0;i<= 4; i++)
{
for (j = 0; j <= 9; j++)
{
//printf("Hi\n");
char fileName[10]="A";
char append[2];

itoa(i,append,10);
strcat(fileName,append);

itoa(j,append,10);
strcat(fileName,append);

printf("i=%d j=%d\n", i,j);
printf("%s\n", fileName);
//FMS()
}
//printf("Anuj=%d\n",i );
}
}

输出

RC4Attack.c:(.text+0x5e): 未定义对 itoa 的引用
RC4Attack.c:(.text+0x8e): undefined reference
itoa'collect2:错误:ld 返回 1 退出状态

最佳答案

标准C 库中没有itoa。相反,请使用 sprintf。

sprintf(string_value, "%d", integer_value);

编辑还可以使用 snprintf 来防止缓冲区溢出。

snprintf(string_value, max_size, "%d", integer_value);

关于C代码int到字符串不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22822173/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com