Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- #include <stdlib.h> // For exit() function
- char *number_1(char tline[]) {
- for (int i = 0, x = strlen(tline); i < x; i++) {
- if (tline[i] == 'a' || tline[i] == 'e' || tline[i] == 'i' || tline[i] == 'o' || tline[i] == 'u' ||
- tline[i] == 'A' || tline[i] == 'E' || tline[i] == 'I' || tline[i] == 'O' || tline[i] == 'U') {
- memmove(&tline[i], &tline[i+1], strlen(tline)-i);
- i--;
- }
- }
- return tline;
- }
- char *number_2(char tline[]) {
- int x = strlen(tline);
- for (int i = 0; i < x; i++) {
- if (i > 0 && i < x && tline[i] == tline[i+1]) {
- memmove(&tline[i], &tline[i+1], x-i);
- x--;
- }
- }
- return tline;
- }
- char *number_3(char tline[]) {
- int alpha_count = 0;
- for (int i = 0, x = strlen(tline); i < x; i++) {
- // if we do not count space as character-to-uppercase, uncomment next and add "}"
- // if (isalpha(tline[i])) { // do not count space as character-to-uppercase
- // if (alpha_count++ % 2 == 0 ) {
- if ( i++ % 2 == 0 ) {
- tline [i] = toupper(tline[i]);
- }
- }
- return tline;
- }
- int main() {
- int number;
- FILE *fip = fopen("input.txt", "r");
- FILE *fop = fopen("output.txt", "w+");
- if (fip == NULL)
- {
- printf("Can't open file!");
- // Program exits if file pointer returns NULL.
- exit(1);
- }
- char line[256]; //magic number of max line size
- printf("Input number of zadazha. Currently available: 1, 2, 3\n");
- scanf("%d", &number);
- while (fgets(line, sizeof(line), fip)) {
- switch (number) {
- case 1: fprintf(fop, "%s", number_1(line)); break;
- case 2: fprintf(fop, "%s", number_2(line)); break;
- case 3: fprintf(fop, "%s", number_3(line)); break;
- default: printf("OH NO! METEORITE RAIN! I SHOULD RUN, BYE!\n");
- }
- }
- fclose(fip);
- fclose(fop);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement