gpt4 book ai didi

c - ITOA函数如何在20行内修复

转载 作者:行者123 更新时间:2023-11-30 15:36:50 31 4
gpt4 key购买 nike

我正在编写 RLE 压缩代码,但 20 行的 itoa 函数出现问题。我该如何解决这个问题?我是 C 语言新手,所以如果您能为我提供部分经过更改的代码,我会很高兴。谢谢你! (抱歉重复,但我无法发表评论)如果您指出我应该插入更改的部分,我将不胜感激!!!!

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

void StringRLE(char *pointer) {
char *rle = new char[strlen(pointer)];
int i = 0;
int rleCount = 1;
char *s = pointer + 1, ch[2] = { 0, 0 };
while (*pointer != '\0') {
if (*pointer == *s)
rleCount++;
else{
_itoa_s(rleCount, rle, 10);
ch[0] = *pointer;
strcat(rle, ch);
puts(rle);
rleCount = 1;
}

pointer++;
s++;
i++;
}
}

错误:

Error C2660 Function Does Not Take 3 Arguments ;No instance of overload function

最佳答案

啊,MSDN 功能...好吧,_itoa_s()需要 4 个参数,而您只给了它三个,因此错误表明它不需要 3 个参数。

errno_t _itoa_s(
int value,
char *buffer,
size_t sizeInCharacters,
int radix
);

“没有重载函数实例”告诉您,接受较少参数的 _itoa_s() 函数不超过 1 个。看起来您缺少 radixsizeInCharacters:

[in] sizeInCharacters
Size of the buffer in single-byte characters or wide characters.
[in] radix
Base of value; which must be in the range 2–36.

关于c - ITOA函数如何在20行内修复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22437597/

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