Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //-----------------------------------------------------------------------------
- // ass-b1.c
- //
- // The program takes a string and interprets it firstly. The first thing which
- // the program does is checks whether the string is either
- // a) Empty
- // b) Too short
- // Should it be either of these two, it returns the values -1 and -2
- // respectively.
- // After that, the program takes the string defined and turns it around
- // with each word being inverted. This is done through the function
- // reversePrint. The output value is a reversed string with each word
- // being reversed separately, as well as starting letters being capitalised
- // and every other letter being lower-case.
- //
- // Group: Group 18, study assistant Kevin Innerebner
- //
- // Authors: Vedad Misirlic 11833774
- //-----------------------------------------------------------------------------
- //
- #include <stdio.h>
- #include <ctype.h>
- int reversePrint(char *name)
- {
- int begin_counter = 0;
- int end_counter = 0;
- int main_counter = 0;
- int space_counter = 0;
- int return_value = 0;
- int check_done = 0;
- for (check_done = 0; check_done < 1; check_done++) {
- if (*name == 0)
- {
- return_value = -1;
- break;
- }
- for (main_counter = 0; (*(name + main_counter)) != 0; main_counter++) {
- if (*(name + main_counter) == 32 && *(name + main_counter + 1) != 0)
- space_counter++;
- }
- if (space_counter == 0) {
- return_value = -2;
- break;
- }
- else
- {
- for (main_counter = 0; (*(name + main_counter)) != 0; main_counter++)
- {
- if (*(name + main_counter) == 32)
- {
- for (end_counter = main_counter - 1; end_counter >= begin_counter; end_counter--)
- {
- if (end_counter == main_counter - 1)
- {
- printf("%c", toupper(*(name + end_counter)));
- }
- else
- {
- printf("%c", tolower(*(name + end_counter)));
- }
- }
- printf(" ");
- begin_counter = main_counter + 1;
- }
- if ((*(name + main_counter + 1)) == 0)
- {
- for (end_counter = main_counter; end_counter >= begin_counter; end_counter--)
- {
- if (end_counter == main_counter)
- {
- printf("%c", toupper(*(name + end_counter)));
- } else
- {
- printf("%c", tolower(*(name + end_counter)));
- }
- }
- }
- }
- return_value = 0;
- }
- }
- return return_value;
- }
- int main() {
- char name[] = "Vedad Misiric";
- reversePrint(name);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement