使用stdin不止一次

时间:2014-11-08 09:45:40

标签: c stdin

我想问一下,如果可以使用以EOF结尾的stdin不止一次。我有类似的东西:

int ColumnCounter = 0; 
int Space = 1;
long IterationCounter = 0;
do
{
    while ((Char = getchar()) != EOF)
        {
            if ((Char != ' ')  && (Space == 1))
                {
                    ColumnCounter++;
                    Space = 0;
                }
            else if (Char == ' ')
                {
                    Space = 1;
                }
            else if (Char == '\n' || Char == '\0')
                {
                    putchar('\n');
                    Space = 0;
                    ColumnCounter = 1;
                    continue;
                }
            if (ColumnCounter == NumberOfCol)
                {
                    putchar(Char);
                }
        }
    ColumnCounter = 0;
    Space = 1;
    IterationCounter = NumberOfCol++;
    IterationCounter++;}
while (IterationCounter < EndingNumberOfCol + 1);

继续下面的评论。

1 个答案:

答案 0 :(得分:0)

是的。就像你一直在做几乎一样!使用以下代码:

int repeat=0; // Don't forget to initialize repeat
int Znak;
do
{
    while ((Znak = getchar()) != EOF)
    {          ...         }
    repeat++; //repeat not reapeat here
}
while (repeat<5); //loop until repeat is less than 5
编辑:我看到你编辑了代码。所以,只需在程序中实现上述逻辑。