Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- int main()
- {
- char ftext[100], otext[100], store;
- int i, a, b;
- printf("Please enter the text to be flipped: ");
- gets(ftext);
- for(i = 0; ftext[i]; i++) /* Converts ftext to lower case before it is coppied to otext*/
- {
- ftext[i] = tolower(ftext[i]);
- }
- strcpy(otext, ftext); /* coppies ftext to otext */
- a = 0; /* sets value of a to 0 */
- b = strlen(ftext) - 1; /* sets value of b to the length of ftext -1 */
- while (a < b) /* function to flip the text around */
- {
- if((ftext[a] <= 57) && (ftext[b] == ' '))
- {
- store = ftext[a];
- ftext[a] = ftext[b];
- ftext[b] = store;
- a++; /*incriment a*/
- b--; /*incriment b*/
- }
- else if((ftext[a] == ' ') && (ftext[b] >= 57))
- {
- store = ftext[a];
- ftext[a] = ftext[b];
- ftext[b] = store;
- a++; /*incriment a*/
- b--; /*incriment b*/
- }
- else if((ftext[a] == ' ') && (ftext[b] == ' '))
- {
- store = ftext[a];
- ftext[a] = ftext[b];
- ftext[b] = store;
- a++; /*incriment a*/
- b--; /*incriment b*/
- }
- else if ((ftext[a] >= 57) && (ftext[b] >= 57))
- {
- store = ftext[a];
- ftext[a] = ftext[b];
- ftext[b] = store;
- a++; /*incriment a*/
- b--; /*incriment b*/
- }
- else if((ftext[a] <= 57) && (ftext[b] > 57))
- {
- a++; /*incriment a*/
- }
- else if((ftext[a] > 57) && (ftext[b] <= 57))
- {
- b--; /*incriment b*/
- }
- }
- printf("flipped ##%s##\n", ftext);
- printf("Preflip ##%s##\n", otext);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement