Friday, 6 July 2012

First character reverse and add extra word

Q. Write a C program to accept a string from user and put the first character of word at the end of string and add one extra character.
Example:
Enter String: This Is A Good Blog
Result: hisTX sIX AX oodGX logBX


Ans.


/*c program for taking first character of every word and put it at the end of word and then add one extra word.*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
 char tmp,str[30];
 int i;
 printf("Enter string : ");
 gets(str);
 printf("\n-- Result of program --\n\n");
 tmp=str[0];
 for(i=1; str[i]!='\0'; i++)
 {
  if(str[i]==' ')
  {
    printf("%cX",tmp);
    printf(" ");
    i++;
    tmp=str[i];
  }
  else
    printf("%c",str[i]);
 }
 printf("%cX",tmp);
 getch();
 return 0;
}


/***************Output*****************/
Output of arrangement character in string C program
Screen shot for reverse each first character of word and adding one extra word C program


Related program:

  1. Reverse all string
  2. Reverse all words but not string
  3. Change title case of string
  4. Display string vertically
  5. Search sub string from main string
  6. Search sub string individual from main string
  7. Position and repetition of character in string

No comments:

Post a Comment