SHARE
TWEET

Untitled

a guest Dec 8th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //-----------------------------------------------------------------------------
  2. // ass-b1.c
  3. //
  4. // The program takes a string and interprets it firstly. The first thing which
  5. // the program does is checks whether the string is either
  6. // a) Empty
  7. // b) Too short
  8. // Should it be either of these two, it returns the values -1 and -2
  9. // respectively.
  10. // After that, the program takes the string defined and turns it around
  11. // with each word being inverted. This is done through the function
  12. // reversePrint. The output value is a reversed string with each word
  13. // being reversed separately, as well as starting letters being capitalised
  14. // and every other letter being lower-case.
  15. //
  16. // Group: Group 18, study assistant Kevin Innerebner
  17. //
  18. // Authors: Vedad Misirlic 11833774
  19. //-----------------------------------------------------------------------------
  20. //
  21.  
  22. #include <stdio.h>
  23. #include <ctype.h>
  24.  
  25. int reversePrint(char *name)
  26. {
  27.   int begin_counter = 0;
  28.   int end_counter = 0;
  29.   int main_counter = 0;
  30.   int space_counter = 0;
  31.   int return_value = 0;
  32.   int check_done = 0;
  33.   for (check_done = 0; check_done < 1; check_done++) {
  34.     if (*name == 0)
  35.     {
  36.       return_value = -1;
  37.       break;
  38.     }
  39.     for (main_counter = 0; (*(name + main_counter)) != 0; main_counter++) {
  40.       if (*(name + main_counter) == 32 && *(name + main_counter + 1) != 0)
  41.         space_counter++;
  42.     }
  43.     if (space_counter == 0) {
  44.       return_value = -2;
  45.       break;
  46.     }
  47.     else
  48.       {
  49.       for (main_counter = 0; (*(name + main_counter)) != 0; main_counter++)
  50.       {
  51.         if (*(name + main_counter) == 32)
  52.         {
  53.           for (end_counter = main_counter - 1; end_counter >= begin_counter; end_counter--)
  54.           {
  55.             if (end_counter == main_counter - 1)
  56.             {
  57.               printf("%c", toupper(*(name + end_counter)));
  58.             }
  59.             else
  60.               {
  61.               printf("%c", tolower(*(name + end_counter)));
  62.               }
  63.           }
  64.           printf(" ");
  65.           begin_counter = main_counter + 1;
  66.         }
  67.         if ((*(name + main_counter + 1)) == 0)
  68.         {
  69.           for (end_counter = main_counter; end_counter >= begin_counter; end_counter--)
  70.           {
  71.             if (end_counter == main_counter)
  72.             {
  73.               printf("%c", toupper(*(name + end_counter)));
  74.             } else
  75.               {
  76.               printf("%c", tolower(*(name + end_counter)));
  77.             }
  78.           }
  79.         }
  80.       }
  81.       return_value = 0;
  82.     }
  83.   }
  84.   return return_value;
  85. }
  86.  
  87.  
  88. int main() {
  89.   char name[] = "Vedad Misiric";
  90.   reversePrint(name);
  91.   return 0;
  92. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top