Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.87 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #include <stdlib.h> // For exit() function
  5.  
  6. char *number_1(char tline[]) {
  7.   for (int i = 0, x = strlen(tline); i < x; i++) {
  8.     if (tline[i] == 'a' || tline[i] == 'e' || tline[i] == 'i' || tline[i] == 'o' || tline[i] == 'u' ||
  9.         tline[i] == 'A' || tline[i] == 'E' || tline[i] == 'I' || tline[i] == 'O'  || tline[i] == 'U') {
  10.       memmove(&tline[i], &tline[i+1], strlen(tline)-i);
  11.       i--;
  12.     }
  13.   }
  14.   return tline;
  15. }
  16.  
  17. char *number_2(char tline[]) {
  18.   int x = strlen(tline);
  19.   for (int i = 0; i < x; i++) {
  20.     if (i > 0 && i < x && tline[i] == tline[i+1]) {
  21.       memmove(&tline[i], &tline[i+1], x-i);
  22.       x--;
  23.     }
  24.   }
  25.   return tline;
  26. }
  27.  
  28. char *number_3(char tline[]) {
  29.   int alpha_count = 0;
  30.   for (int i = 0, x = strlen(tline); i < x; i++) {
  31. // if we do not count space as character-to-uppercase, uncomment next and add "}"
  32. //      if (isalpha(tline[i])) { // do not count space as character-to-uppercase
  33. //          if (alpha_count++ % 2 == 0 ) {
  34.     if ( i++ % 2 == 0 ) {
  35.       tline [i] = toupper(tline[i]);
  36.     }
  37.   }
  38.   return tline;
  39. }
  40.  
  41. int main() {
  42.   int number;
  43.   FILE *fip = fopen("input.txt", "r");
  44.   FILE *fop = fopen("output.txt", "w+");
  45.   if (fip == NULL)
  46.   {
  47.     printf("Can't open file!");
  48.     // Program exits if file pointer returns NULL.
  49.     exit(1);
  50.   }
  51.  
  52.   char line[256]; //magic number of max line size
  53.   printf("Input number of zadazha. Currently available: 1, 2, 3\n");
  54.   scanf("%d", &number);
  55.   while (fgets(line, sizeof(line), fip)) {
  56.     switch (number) {
  57.       case 1: fprintf(fop, "%s", number_1(line)); break;
  58.       case 2: fprintf(fop, "%s", number_2(line)); break;
  59.       case 3: fprintf(fop, "%s", number_3(line)); break;
  60.       default: printf("OH NO! METEORITE RAIN! I SHOULD RUN, BYE!\n");
  61.     }
  62.   }
  63.  
  64.   fclose(fip);
  65.   fclose(fop);
  66.  
  67.   return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement