C program to find space and Use New line and Capitalize first word of all line

-- Leave a Comment
Hello this is a program to convert a Line string to multyline by inserting newline in every space and Capatalize the first word of all line.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<stdio.h>
void main()
    {
    char asent[100];
    int i;
    printf("Enter a line of string:- \n");
    gets(asent);
    puts(asent);
    for (i=0;asent[i]!='\0';i++)
        {
        if (asent[0]>='a' && asent[0]<='z')
            asent[0]=asent[0]-32;
        if(asent[i]==' ')
            {
                asent[i]='\n';
                if(asent[i+1]>='a' && asent[i+1]<='z')
                    asent[i+1]=asent[i+1]-32;
            }
        }
    puts(asent);

    }

Write a program to Read the string "My name is sagar devkota" and convert it in the following form using loop:-
My
Name
Is
Sagar
Devkota

Here in the above program we check the Case of first word and make it capital if needed and check every space and replace it with newline and check the case of next word and change its case to Uppercase and display at last.

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