C program for swapping the string, C/C++ Programming

C Program for SWAPPING THE STRING

#include conio.h>

#include stdio.h>

void main()

{

          char a[50],temp=0;

          int i=0,c=0,c1=0,l=0;

          clrscr();

          printf("ENTER THE STRING= ");

          flushall();

          do

          {

                   a[i++]=getchar();

          }while(a[i-1]!='\n');

          a[i]='\0';

          for(i=0;a[i]!='\0';i++)

          {

                   if(a[i]==' ' || a[i]=='\n')

                   {

                             c++;

                   }

          }

printf("\nTHE TOTAL NO OF WORDS BEFORE SWAPING IS  %d\n\n",c);

          l=strlen(a);

          l--;

          for(i=0;a[i]!='\0';i++)

          {

                   temp=a[i];

                   a[i]=a[i+1];

                   a[i+1]=temp;

                   i++;

          }

 

          for(i=0;a[i]!=0;i++);

                   if(l%2!=0)

                   {

                             temp=a[i-2];

                             a[i-2]=a[i-1];

 

                             a[i-1]=temp;

                   }       

                   else

                   {

                             a[i]='\n';

                             a[i+1]='\0';

                   }

          printf("%s",a);

          for(i=0;a[i]!='\0';i++)

          {

                   if(a[i]==' ' || a[i]=='\n')

                   {

                             c1++;

                   }

          }

printf("\nTHE TOTAL NO OF WORDS AFTER SWAPING IS %d\n\n",c1);

getch();

}

 

OUTPUT :

ENTER THE STRING: KAMLESH D MENGAR

THE TOTAL NO OF BEFORE SWAPPING 3

AKLMSE H DEMGNRA

THE TOTAL NO OF AFTER SWAPPING 3

 

Posted Date: 9/10/2012 7:34:18 AM | Location : United States







Related Discussions:- C program for swapping the string, Assignment Help, Ask Question on C program for swapping the string, Get Answer, Expert's Help, C program for swapping the string Discussions

Write discussion on C program for swapping the string
Your posts are moderated
Related Questions
C program to print L diagonal triangle: void main() {                 int i=0,j=0;                 int arr[rows][cols];                 for (i=0; i

A Padovan string P(n) for a natural number n is defined as: P(0) = ‘X’ P(1) = ‘Y’ P(2) = ‘Z’ P(n) = P(n-2) + P(n-3), n>2 where + denotes string concate program 1 : package test

Question: (a) Describe what are dynamic pointers. Show their memory representations diagrammatically. (b) Write short notes about pointers in arrays, paying attention on

Poker Room auto seat program Project Description: I want a script for an online poker site. It requires to be scanning all the available tables and when the table meets certa

How are postfix and prefix versions of operator++ () differentiated? A: The postfix version of operator++ () contain a dummy parameter of type int. The prefix version does not c

Problem : (a) Stacks can be implemented using arrays. Write down the following C or C++ function to (i) create a stack (ii) add an element to a stack (push). (b) Expl

Explain some String Oriented Library Functions? To make simpler string processing we can use special string oriented library functions. Mainly the C compilers include library f

Define the Processing of a Structure? The members of structure are typically processed individually as separate entities. So we must be able to access the individual structure

Receive 3 numbers and display them in ascending order from smallest to largest ed#

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points can b