Wednesday, August 8, 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

No comments:

Post a Comment