无法理解C程序中Append()中的代码
Unable to understand the code in the Append() in a C program
我正在试着阅读我在网上遇到的一个程序。我一直在努力阅读和理解这个程序,我已经理解了所有的代码行,除了下面给出的行。如果你们能帮我理解这些台词,我将不胜感激。完整的代码可以在这个站点
找到。 while(1)
{
c=getch();
if(c==19)
goto end3;
if(c==13)
{
c='n';
printf("nt");
fputc(c,fp1);
}
else
{
printf("%c",c);
fputc(c,fp1);
}
}
while(1) // Loop forever.
{
c=getch(); // read a character from stdin.
if(c==19) // If the character read is 'CTRL-S',
goto end3; // jump to the 'end3' label.
if(c==13) // If the character read is '(Carriage) Return',
{
c='n'; // Set 'c' to be a C 'newline' character.
printf("nt"); // Write a 'newline' and a 'tab' character to stdout.
fputc(c,fp1); // Write the value of 'c' to the fp1 stream.
}
else // If the character read is -not- '(Carriage) Return',
{
printf("%c",c); // Write the character to stdout.
fputc(c,fp1); // Write the value to the fp1 stream.
}
}
因为这是一些非常丑陋的代码,这里是一个更简单的重写:
while(1)
{
if((c=getch()) == 19) // If Ctrl+S, end this While-Loop
{
break; // Goto is EVIL!
}
fputc((c=='r')? (puts("nt"), 'n') : // Convert Return to n, OR
(putchar(c), c ), fp1); // Put out exactly the char that was input.
}
相关文章:
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 代码在main()中运行,但在函数中出现错误
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- 编译包含字符串的代码时遇到问题
- 我在c++代码中生成了一个运行时#3异常
- 如何在linux终端中同时编译和运行c++代码
- 为cl.exe(Visual Studio代码)指定命令行C++版本
- 在Linux for Windows上编译C++代码时出错
- 我的字符计数代码计算错误.为什么
- 孤立代码块在结构中引发异常
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- 此代码是否违反一个定义规则
- 为什么我的代码在输出中增加了93天
- 我的简单if-else语句是如何无法访问的代码
- 使用动态分配的数组会导致代码分析发出虚假的C6386缓冲区溢出警告
- 为什么在这个代码结束循环中没有得到结束
- 在c代码之间共享数据的最佳方式
- 无法理解C程序中Append()中的代码