Advertisement
cd62131

SwapCase

Feb 4th, 2014
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.62 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #define N 5
  6. int main(void) {
  7.   char *input = (char *) malloc(N);
  8.   int count = 0;
  9.   int size = 1;
  10.   while (1) {
  11.     if (count >= size * N) {
  12.       char *new = (char *) malloc(++size * N);
  13.       input = strcpy(new, input);
  14.     }
  15.     char c;
  16.     if ((c = (char) getchar()) == '\n') break;
  17.     input[count++] = c;
  18.     input[count] = '\0';
  19.   }
  20.   for (int i = 0; input[i]; i++) {
  21.     char c = input[i];
  22.     if (islower(c)) putchar(toupper(c));
  23.     else if (c) putchar(tolower(c));
  24.     else putchar(c);
  25.   }
  26.   puts("");
  27.   return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement