commit 52aa11d04e4aaea80d4985647e2bdf7019fb9509 Author: DIvan2000 Date: Sat Nov 30 13:06:00 2024 +0400 first commit diff --git a/.depend b/.depend new file mode 100644 index 0000000..8ab4a9d --- /dev/null +++ b/.depend @@ -0,0 +1,4 @@ +main.o: src/main.c src/scanFile.h src/myString.h +myAlphabet.o: src/myAlphabet.c src/myAlphabet.h src/myString.h +myString.o: src/myString.c src/myString.h +scanFile.o: src/scanFile.c src/scanFile.h src/myString.h src/myAlphabet.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cd531cf --- /dev/null +++ b/.gitignore @@ -0,0 +1,54 @@ +# ---> C +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..945039d --- /dev/null +++ b/Makefile @@ -0,0 +1,25 @@ +TARGET ?= VowelOrConsonant +CC ?= gcc + +PREF_SRC = ./src/ +PREF_OBJ = ./obj/ + +SRC = $(wildcard $(PREF_SRC)*.c) +OBJ = $(patsubst $(PREF_SRC)%.c, $(PREF_OBJ)%.o, $(SRC)) + +$(TARGET) : $(OBJ) + $(CC) $(OBJ) -o $(TARGET) + +depend: .depend + +.depend: $(SRC) + rm -f "$@" + $(CC) -MM $^ > "$@" + +-include .depend + +$(PREF_OBJ)%.o : $(PREF_SRC)%.c + $(CC) -c $< -o $@ -D_PROG_NAME=\"$(TARGET)\" + +clean : + rm $(TARGET) $(PREF_OBJ)*.o *.d diff --git a/README.md b/README.md new file mode 100644 index 0000000..fdcc332 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# InfLab3 diff --git a/VowelOrConsonant b/VowelOrConsonant new file mode 100755 index 0000000..a2e061a Binary files /dev/null and b/VowelOrConsonant differ diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..fc93823 --- /dev/null +++ b/src/main.c @@ -0,0 +1,24 @@ +#include +#include "scanFile.h" + +int main(int argc,char *argv[]){ + FILE* in; + FILE* out; + + printf("Лабораторная работа №3\n\nВариант №1, 6106, автор: Морозов Иван\n\n"); + + if(argc!=3){ + printf("Неверные аргументы! Используйте \"" _PROG_NAME " <имя_входного_файла> <имя_выходного_файла>\"\n"); + return 1; + } + + in = fopen(argv[1], "r"); + out = fopen(argv[2], "w"); + + processFile(in, out); + + fclose(in); + fclose(out); + + return 0; +} diff --git a/src/myAlphabet.c b/src/myAlphabet.c new file mode 100644 index 0000000..0170c29 --- /dev/null +++ b/src/myAlphabet.c @@ -0,0 +1,20 @@ +#include +#include "myAlphabet.h" + +char isVovel(int c){ + c = tolower(c); + return(c=='e'||c=='i'||c=='a'||c=='o'||c=='u'||c=='y'); +} + +char areVovelMore(MyString str){ + int vovels = 0; + int consonants = 0; + for(unsigned int i = 0; i < str.len; i++){ + char c = str.arr[i]; + if(isalpha(c)){ + if(isVovel(c)) vovels++; + else consonants++; + } + } + return vovels>consonants; +} diff --git a/src/myAlphabet.h b/src/myAlphabet.h new file mode 100644 index 0000000..c72bcd7 --- /dev/null +++ b/src/myAlphabet.h @@ -0,0 +1,9 @@ +#ifndef MY_ALPHABET_H_ +#define MY_ALPHABET_H_ + +#include "myString.h" + +char isVovel(int c); +char areVovelMore(MyString str); + +#endif diff --git a/src/myString.c b/src/myString.c new file mode 100644 index 0000000..764c17f --- /dev/null +++ b/src/myString.c @@ -0,0 +1,37 @@ +#include +#include +#include "myString.h" + +static void reallocString(MyString* str); + +MyString newString(unsigned int init_capacity){ + MyString str; + str.arr = (char*) malloc(init_capacity); + str.len = 0; + str.capacity = init_capacity; + return str; +} +void addCharToString(MyString* str, char c){ + if(str->len >= str->capacity){ + reallocString(str); + } + (str->arr)[str->len] = c; + (str->len)++; +} + +void freeString(MyString* str){ + free(str->arr); + str->len = 0; + str->capacity = 0; + str->arr = NULL; + str = NULL; +} + +static void reallocString(MyString* str){ + str->arr = realloc(str->arr, (str->capacity)*2); + (str->capacity)*=2; + if(str->arr==0){ + printf("Нет памяти для строки 0x%lX", (unsigned long) str); + exit(1); + } +} diff --git a/src/myString.h b/src/myString.h new file mode 100644 index 0000000..0b6f270 --- /dev/null +++ b/src/myString.h @@ -0,0 +1,15 @@ +#ifndef MY_STRING_H_ +#define MY_STRING_H_ + +typedef struct myStr +{ + unsigned int capacity; + unsigned int len; + char* arr; +} MyString; + +MyString newString(unsigned int init_capacity); +void addCharToString(MyString* str, char c); +void freeString(MyString* str); + +#endif diff --git a/src/scanFile.c b/src/scanFile.c new file mode 100644 index 0000000..5cd06c5 --- /dev/null +++ b/src/scanFile.c @@ -0,0 +1,41 @@ +#include +#include +#include "scanFile.h" +#include "myString.h" +#include "myAlphabet.h" + +#define DEFAULT_BUFFER_SIZE 16 + +void processFile(FILE* in, FILE* out){ + while(!feof(in)){ + MyString str = newString(DEFAULT_BUFFER_SIZE); + scanString(&str, in); + processString(out, str); + freeString(&str); + } +} + +void scanString(MyString* dst, FILE* src){ + for(char ch = fgetc(src); ch != '\n' && !feof(src); ch = fgetc(src)){ + addCharToString(dst, ch); + } +} + +void processString(FILE* out, MyString str){ + char isVovelsMore = areVovelMore(str); + char letters['z'-'a']; + for(char i = 'a'; i < 'z'; i++){ + letters[i-'a']=0; + } + for(unsigned int i = 0; i < str.len; i++){ + char ch = str.arr[i]; + if(isalpha(ch)){ + ch = tolower(ch); + if(!letters[ch-'a'] && (isVovelsMore == isVovel(ch))){ + fputc(ch, out); + } + letters[ch-'a']=1; + } + } + fputc('\n', out); +} diff --git a/src/scanFile.h b/src/scanFile.h new file mode 100644 index 0000000..ea73942 --- /dev/null +++ b/src/scanFile.h @@ -0,0 +1,11 @@ +#ifndef SCANFILE_H_ +#define SCANFILE_H_ + +#include +#include "myString.h" + +void processFile(FILE* in, FILE* out); +void scanString(MyString* dst, FILE* src); +void processString(FILE* out, MyString str); + +#endif diff --git a/test_files/test1_in b/test_files/test1_in new file mode 100644 index 0000000..5e11dfd --- /dev/null +++ b/test_files/test1_in @@ -0,0 +1,2 @@ +bbad, sdiv +aaagh yd diff --git a/test_files/test1_out b/test_files/test1_out new file mode 100644 index 0000000..f92793d --- /dev/null +++ b/test_files/test1_out @@ -0,0 +1,3 @@ +bdsv +ay + diff --git a/test_files/test2_in b/test_files/test2_in new file mode 100644 index 0000000..d037892 --- /dev/null +++ b/test_files/test2_in @@ -0,0 +1,2 @@ +Shall I compare thee to a summer’s day? +Thou art more lovely and more temperate… diff --git a/test_files/test2_out b/test_files/test2_out new file mode 100644 index 0000000..55cf5a0 --- /dev/null +++ b/test_files/test2_out @@ -0,0 +1,3 @@ +shlcmprtd +thrmlvndp + diff --git a/test_files/test3_in b/test_files/test3_in new file mode 100644 index 0000000..8a46570 --- /dev/null +++ b/test_files/test3_in @@ -0,0 +1,3 @@ + The quick brown fox jumps over the lazy dog + ackdaws love my big sphinx of quartz + The five boxing wizards jump quickly diff --git a/test_files/test3_out b/test_files/test3_out new file mode 100644 index 0000000..d2f6e89 --- /dev/null +++ b/test_files/test3_out @@ -0,0 +1,4 @@ +thqckbrwnfxjmpsvldg +ckdwslvmbgphnxfqrt +thfvbxngwrdsjmpqckl +