欲输入:C字符串数组问题
ABC DEF GHI JKL
和输出应为:
abc
def
ghi
jkl
欲每个字符串存储在数组中然后使用for循环打印每个位置。
我有这样的代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char vector[100];
int i = 0;
int aux = 0;
while (i < 5)
{
scanf("%s", &vector[i]);
i++;
aux+= 1;
}
for (i=0;i<aux;i++)
{
printf("%s\n", &vector[i]);
}
return 0;
}
我在做什么错?
第二个问题:
如何更改代码停止阅读我的投入,当我按CTRL d并打印输出?
谢谢。完成你所说的,它的工作。改变while循环while(我<5 && scanf(“%s”,vector [i])!= EOF)'现在它停止了我按ctrl d,但如果我输入'abc'并按下ctrl d it在“c”输入后打印'a',在新行上打印'b'和'c'。我该如何改变它? – Favolas 2011-04-03 17:09:13
@Favolas你可以发布你的新代码?用它回答你(显然是新的)问题会更容易。 – rlc 2011-04-03 21:01:20
感谢您的帮助。这是http://stackoverflow.com/questions/5535916/c-while-loop-stopping-at-e-但--printing-result-in-a-new-line – Favolas 2011-04-04 08:01:30