gpt4 book ai didi

c - 将文件放入链接列表时出现空格

转载 作者:行者123 更新时间:2023-11-30 17:22:23 25 4
gpt4 key购买 nike

我正在尝试将文件的内容复制到 LIFO 中的链接列表中。我的文件具有此数据 QWERTY 但当我将其存储在链接列表中时,它会存储为 - YTREWQ Y 之前有一些空格。额外的空格从哪里来?这是我的代码- http://ideone.com/siR5dI

最佳答案

空白是添加到 LIFO 队列的文件末尾的“\n”换行符或行终止符。

$ ./LIFO.out inputfile 
0:Q
1:W
2:E
3:R
4:T
5:Y
6:

$ cat inputfile
QWERTY
$

上面是我通过更改以下行获得的输出:

 int count = 0; // Add count initialization
while(ch!=EOF)
{
printf("%d:%c\n",count++,ch); // Print count to see how many chars are found in the file
head1=insert(ch,head1);
ch=getc(file1);
}
<小时/>

要打印 ascii 值,请更新上面的代码片段:

printf("%d:%c(%d)\n",count++,ch,ch);

它给了我以下输出:

0:Q(81)
1:W(87)
2:E(69)
3:R(82)
4:T(84)
5:Y(89)
6:
(10)

那10就是New Line换行的ascii值。

关于c - 将文件放入链接列表时出现空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28036137/

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