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

标签 c string int

这是我使用 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/

相关文章:

java - 字符串比较 : individual comparison Vs appended string comparison

c++ - C++中未声明的字符串

c++ - 如何在C++中将字符串转换为整数

c - 我的字符串传递到 C 中的指针函数时出错?

c - 使用 int 或枚举值访问结构字段

java - 检测一个字符串是否只由一种字符组成

c# - 将带逗号的字符串转换为 double 和 int 是不同的。为什么?

c - 用汇编语言打印数组元素

c - <inttypes.h> 的良好介绍

c++ - 使用 str.at(x) 将字符串转换为 int