8.08.2012

Split string vertically only words not characters

Q. Write a C program to print the string vertically only words not all characters.

For example:

string: You are genius to learn C language
result:
     You
     are
     genius
     to
     learn
     C
     Language

Ans.

/*c program to print string vertically only words not characters*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int i;
 char str[30];
 printf("Enter any string: ");
 gets(str);
 for(i=0; str[i]!='\0'; i++)
 {
  if(str[i]==' ')
     printf("\n");
  else
     printf("%c",str[i]);
 }
 getch();
 return 0;
}

/***********Output***********/

Output of print string vertical only words not characters C program
Screen shot for print string vertical only
words not characters C program

2 comments:

  1. How about in reversed? Pls Help!

    ReplyDelete
    Replies
    1. @Edwin Moises Adigue,

      Describe your questions. All string related C program at:


      http://cprogrammingcodes.blogspot.in/2012/07/reverse-all-string.html

      Delete