Quantcast
Channel: how to create each word of input to start a new line - Stack Overflow
Viewing all articles
Browse latest Browse all 2

how to create each word of input to start a new line

$
0
0

Hey i am trying to print each word on a new line. My EOF is also not working and was wondering why this is. i have made it to scan for a space and then print new line.

#include <stdio.h>
#include <ctype.h>

int main(void)
{
    char ch;

    while ((ch = getchar()) != '#')
        putchar(ch);

int nextChar;
    nextChar = getchar();
    while (nextChar != '\n' && nextChar != EOF);
    {
        if (ch== ' ')
        {
            printf("\n");
        }
        else
        {
            putchar(ch);
        }
        {
            ch = getchar();
        }
        printf("\n");

        {
            scanf("%lc",&nextChar);
            printf("%c",nextChar);
        }

        return 0;
    }
}

just for example input: Stackoverflow is great
output:
Stackoverflow
is
great

Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>