我正在尝试阅读我在网上遇到的一个程序。我一直在努力阅读和理解该程序,我已经理解了除下面给出的行之外的所有代码行。如果你们都能帮我理解这些界限,我将非常感谢你们。完整代码可在this site
找到 while(1)
{
c=getch();
if(c==19)
goto end3;
if(c==13)
{
c='\n';
printf("\n\t");
fputc(c,fp1);
}
else
{
printf("%c",c);
fputc(c,fp1);
}
}
答案 0 :(得分:2)
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("\n\t"); // 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.
}
}
答案 1 :(得分:-1)
因为这是一些非常难看的代码,所以这里的重写更简单:
while(1)
{
if((c=getch()) == 19) // If Ctrl+S, end this While-Loop
{
break; // Goto is EVIL!
}
fputc((c=='\r')? (puts("\n\t"), '\n') : // Convert Return to \n, OR
(putchar(c), c ), fp1); // Put out exactly the char that was input.
}