37 lines
841 B
C
37 lines
841 B
C
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <memory.h>
|
|
|
|
int main(int argc, char *argv[]) {
|
|
if (argc != 2) {
|
|
printf("Usage: rm_vowels <file>\n");
|
|
exit(-1);
|
|
}
|
|
|
|
FILE * file = fopen(argv[1], "r+");
|
|
if (file==NULL) {
|
|
perror("Error while opening file");
|
|
}
|
|
|
|
fseek(file, 0, SEEK_END);
|
|
int file_size = ftell(file);
|
|
fseek(file, 0, SEEK_SET);
|
|
|
|
char * f = malloc(sizeof(char) * file_size);
|
|
fread(f, sizeof(char), file_size, file);
|
|
|
|
fclose(file);
|
|
file = fopen(argv[1], "w+");
|
|
|
|
for(int i = 0; i<file_size; i++) {
|
|
if (!(f[i]=='a' || f[i]=='e' || f[i]=='i' || f[i]=='o' || f[i]=='u' || f[i]=='y' || f[i]=='A' || f[i]=='E' || f[i]=='I' || f[i]=='O' || f[i]=='U' || f[i]=='Y')){
|
|
fputc(f[i], file);
|
|
}
|
|
}
|
|
|
|
fclose(file);
|
|
|
|
return 0;
|
|
}
|
|
|