C,而循环在新线停在EOF但打印效果 [英] C While loop stopping at EOF but printing result in a new line
本文介绍了C,而循环在新线停在EOF但打印效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的code:
的#include<&stdio.h中GT;
#包括LT&;&stdlib.h中GT;
#包括LT&;&string.h中GT; 诠释的main()
{
炭载体[5] [100];
INT I = 0;
INT AUX = 0;
而(ⅰ小于5&放大器;&放大器; scanf的(%S,矢量[I])= EOF!)
{
我++;
AUX + = 1;
} 对于(i = 0; I<辅助;我++)
{
的printf(%S \\ n,矢量[I]);
}
返回0;
}
它做我想要什么,但我仍然有一些问题。
第一个问题:(解决)
如果我输入 A B C D E F G H I J
的输出是:
A B C D E F G H I JA
b
C
ð
Ë
愿意我可以做我闻preSS CTRL-D它打印,在新行的第一个输出?
事情是这样的:
A B C D E F G H I J
一个
b
C
ð
Ë
第二个问题:
如果我输入 A B C
为什么我要preSS超过一次CTRL-D打印输出?
问候,
FAvolas
解决方案
的printf(\\ n%S,矢量[I]);
简单
I have this code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char vector[5][100];
int i = 0;
int aux = 0;
while (i <5 && scanf("%s", vector[i])!=EOF)
{
i++;
aux+= 1;
}
for (i=0;i<aux;i++)
{
printf("%s\n", vector[i]);
}
return 0;
}
Its doing what I want but still I have some problems.
First question: (solved)
If I input a b c d e f g h i j
the output is:
a b c d e f g h i ja
b
c
d
e
Want can I do to wen I press CTRL-D it prints, the first output in a new line? Something like this:
a b c d e f g h i j
a
b
c
d
e
Second question:
If I input a b c
why do I have to press more than one time CTRL-D to print the output?
Regards,
FAvolas
解决方案
printf("\n%s", vector[i]);
Simply
这篇关于C,而循环在新线停在EOF但打印效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文