Advertisement
Guest User

Untitled

a guest
May 27th, 2015
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.65 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main()
  5. {
  6.  char ftext[100], otext[100], store;
  7.  int i, a, b;
  8.  
  9.  printf("Please enter the text to be flipped: ");
  10.  gets(ftext);
  11.  for(i = 0; ftext[i]; i++) /* Converts ftext to lower case before it is coppied to otext*/
  12.   {
  13.    ftext[i] = tolower(ftext[i]);
  14.   }
  15.  
  16.   strcpy(otext, ftext); /* coppies ftext to otext */
  17.  
  18.   a = 0; /* sets value of a to 0 */
  19.   b = strlen(ftext) - 1; /* sets value of b to the length of ftext -1 */
  20.  
  21.    while (a < b) /* function to flip the text around */
  22.     {
  23.      if((ftext[a] <= 57) && (ftext[b] == ' '))
  24.       {
  25.        store = ftext[a];
  26.        ftext[a] = ftext[b];
  27.        ftext[b] = store;
  28.        a++; /*incriment a*/
  29.        b--; /*incriment b*/
  30.       }
  31.      else if((ftext[a] == ' ') && (ftext[b] >= 57))
  32.       {
  33.        store = ftext[a];
  34.        ftext[a] = ftext[b];
  35.        ftext[b] = store;
  36.        a++; /*incriment a*/
  37.        b--; /*incriment b*/
  38.       }
  39.      else if((ftext[a] == ' ') && (ftext[b] == ' '))
  40.       {
  41.        store = ftext[a];
  42.        ftext[a] = ftext[b];
  43.        ftext[b] = store;
  44.        a++; /*incriment a*/
  45.        b--; /*incriment b*/
  46.       }
  47.      else if ((ftext[a] >= 57) && (ftext[b] >= 57))
  48.       {
  49.        store = ftext[a];
  50.        ftext[a] = ftext[b];
  51.        ftext[b] = store;
  52.        a++; /*incriment a*/
  53.        b--; /*incriment b*/
  54.       }
  55.      else if((ftext[a] <= 57) && (ftext[b] > 57))
  56.       {
  57.        a++; /*incriment a*/
  58.       }
  59.      else if((ftext[a] > 57) && (ftext[b] <= 57))
  60.       {
  61.        b--; /*incriment b*/
  62.       }
  63.     }
  64.    
  65.  printf("flipped ##%s##\n", ftext);
  66.  printf("Preflip ##%s##\n", otext);
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement