Advertisement
Guest User

Untitled

a guest
May 27th, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.13 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] > 96) && (ftext[b] > 96))
  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] <= 96) && (ftext[a] == ' ') && (ftext[b] > 96))
  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] > 96) && (ftext[b] <= 96) && (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] > 96) && (ftext[b] <= 96) && (ftext[b] != ' '))
  48.       {
  49.         b--; /*incriment b*/
  50.       }
  51.      else if ((ftext[a] <= 96) && (ftext[b] <= 96)  && (ftext[a] != ' ') && (ftext[b] != ' '))
  52.       {
  53.         a++; /*incriment a*/
  54.         b--; /*incriment b*/
  55.       }
  56.      else if ((ftext[a] == ' ') && (ftext[b] == ' '))
  57.       {
  58.         a++; /*incriment a*/
  59.         b--; /*incriment b*/
  60.       }
  61.      else if ((ftext[a] > 96) && (ftext[b] <= 96)  && (ftext[b] != ' '))
  62.       {
  63.         b--; /*incriment b*/
  64.       }
  65.      else if ((ftext[a] <= 96) && (ftext[b] > 96)  && (ftext[a] != ' '))
  66.       {
  67.         a++; /*incriment a*/
  68.       }
  69.      else
  70.       {
  71.         store = ftext[a];
  72.         ftext[a] = ftext[b];
  73.         ftext[b] = store;
  74.         a++; /*incriment a*/
  75.         b--; /*incriment b*/
  76.       }
  77.     }
  78.    
  79.  printf("flipped ##%s##\n", ftext);
  80.  printf("Preflip ##%s##\n", otext);
  81. return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement