gpt4 book ai didi

执行垃圾邮件时,C 函数/对象未返回一致的输出

转载 作者:行者123 更新时间:2023-11-30 19:27:07 26 4
gpt4 key购买 nike

我正在开发一个小型项目,它将数据库存储在本地文件中并对其进行操作。我对编程还是新手,因此这种输出的随机性超出了我调试的专业知识。目前的代码很大,所以我只粘贴相关的内容。

extern void returnRecord(FILE *fp, fpos_t pos, char *retArr)
{
char tok = delim; //for strtok (delimiter = control char 21)
char tmpArr[612]; //for strtok
char *segment; //pointer to save strtok return
fsetpos(fp, &pos); //beginning of the record
fgets(tmpArr, 611, fp);
strtok(tmpArr,&tok);
strcpy(retArr, tmpArr);
strcat(retArr, "\n");
segment = strtok(NULL, &tok); //tmpArr now has the author name

int tmpCount = 0;
char c = segment[0];
int counter = strlen(retArr);
while((c != 6) && (c != 0))
{
retArr[counter++] = c;
c = segment[++tmpCount];
}
retArr[counter++] = '\n';



segment = strtok(NULL, &tok); //tmpArr now has the rack number

tmpCount = 0;
c = segment[tmpCount++];
while((c != 6) && (c != 0))
{
retArr[counter++] = c;
c = segment[tmpCount++];
}

retArr[counter++] = '\n';


segment = strtok(NULL, &tok); //tmpArr now has the book title

tmpCount = 0;
c = segment[tmpCount++];
while((c != 6) && (c != 0) && (c != '\n'))
{
retArr[counter++] = c;
c = segment[tmpCount++];
}

retArr[counter] = '\0';
return;
}

下面不是 C 语言,而是我数据库中示例记录的描述:

<...> everything inside is my explanation
<6s> means a bunch of buffer characters that are all 0x06

3<delim>Isaac Newton<6s><delim>3<6s><delim>Philosophiæ Naturalis Principia Mathematica<6s><new line only if it's not the final record>

(delim is: #define delim 21 //at the top)

可能有一些冗余,但优化不是我直接关心的问题,因为输出 (char *retArr) 并不总是一致的。以下是我在发送垃圾邮件可执行文件时的一些输出。

printf("%s\n strlen: %d\n", ret2, strlen(ret2)); //print code
(the first execution here shows the full correct output)
sflash@debian:~/Documents/AOHI/experimental/books$ ./exe
6
Stress test | boooiafnakekjfn/;
4124
e0q-pjrnoibq3uitu0o;@lt@qjtoilqnkubneugbq3tq3
strlen: 84
sflash@debian:~/Documents/AOHI/experimental/books$ ./exe
6
Stress test | boooiafnakekjfn/;
41245
e0q-pjrn
strlen: 48
sflash@debian:~/Documents/AOHI/experimental/books$ ./exe
6
Stress test | boooiafnakekjfn/;
41
45
strlen: 39

当我快速运行程序时,代码似乎跳过了一些迭代。解决这个问题非常重要,因为我打算在循环内调用这个函数/对象。

最佳答案

问题正如一些程序员指出的那样,我一直使用 strtok() 错误且数组大小不匹配。分隔符必须以 NULL 字符终止。

关于执行垃圾邮件时,C 函数/对象未返回一致的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56074483/

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