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
Derived Data Type: Array is derived data type to store large collection of data of only one data type. int mark[100]; char names[25]; Function: will be discussed early

Use 16 digit credit card numbers that contain 15 digits an 1 check digit. The format of the card number consists of the 15 digits followed by the check digit. The check digit is co

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

derivations 1. Regardless of the type of derivation, private members are inherited by the derived class, but cannot be accessed by the new member function of the derived class,

Variable Declaration This declaration of variables in the C language is permitted only in the starting of their block, prior to executable program statements. In C++ declaratio

find area uder the curve y=f(x) between x=a and x=b   #include float start_point, /* GLOBAL VARIABLES */ end_point, total_area; in

Project Description: I play this game called mobstar (mobstar) and I would like the program to grade my account for me. It would require doing a crime, GTA, jail busting, lead a

Implement the search property from catalogue menu option.  After selecting this option the user should be asked to specify the property using the following sub-menu: 1. Specif

a program that declares and prompts the user to enter two integer and performs the five arithmetic operations

want the codings for these topic in ur experts minds.com