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
PROCEDUAL PROGRAMMING INTRODUCTION


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


Create Complex number using constructor: class complex                                 {                                                   private:

What are some guidelines / "rules of thumb" for overloading operators? A: Here are a few guidelines / rules of thumb .Use common sense. If your overloaded operator makes life si

No. it's not required The C++ language guarantees that delete p will do nothing if p is equivalent to NULL. As you might get the test backwards, and as most testing methodologie

Define  C o ns t a n t a r g u me n t : T h e a r gu m e n t c a n b e a c on s t a n t a r gu m e n t .    T h e c o

Explain Object-oriented programming Object-oriented programming (OOP) attempts to meet these requirements, providing methods for managing enormous complexity, achieving reuse o

For this program you will add and test 2 new member functions to the IntSLList class posted on the website. The two member functions are: insertByPosn(int el, int pos) Assuming t