Program to Read a string and print Newline in every word

-- Leave a Comment
Hello Read a String from Users and Print It in Multi line using new line after every words. Read a String "my name is sagar Devkota" and Print it as:-
My
Name
Is
Sagar
Devkota

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include<stdio.h>
void nline(char []);
void main()
    {
    char asent[100];
    int i;
    printf("Enter a line of string:- \n");
    gets(asent);
    nline(asent);
    puts(asent);

    }
void nline(char thesent[100])
    {
    int i;
    for (i=0;thesent[i]!='\0';i++)
        {
        if (thesent[0]>='a' && thesent[0]<='z')
            thesent[0]=thesent[0]-32;
        if(thesent[i]==' ')
            {
                thesent[i]='\n';
                if(thesent[i+1]>='a' && thesent[i+1]<='z')
                    thesent[i+1]=thesent[i+1]-32;
            }
        }
    }

Here we Check the case of First and make it capital if it was small. Then check every space and replace it with Newline "\n". and Make Capital all after that space.

Hello This is Sagar Devkota. Studying Bachelor of Software Engineering at Pokhara University. I know something about Linux, Android, Java, Nodejs, Unity3D and 3 dots :)

0 comments:

Post a Comment