first commit
This commit is contained in:
		
						commit
						52aa11d04e
					
				
							
								
								
									
										4
									
								
								.depend
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								.depend
									
									
									
									
									
										Normal file
									
								
							| @ -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 | ||||
							
								
								
									
										54
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -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 | ||||
| 
 | ||||
							
								
								
									
										25
									
								
								Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								Makefile
									
									
									
									
									
										Normal file
									
								
							| @ -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 | ||||
							
								
								
									
										
											BIN
										
									
								
								VowelOrConsonant
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								VowelOrConsonant
									
									
									
									
									
										Executable file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										24
									
								
								src/main.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								src/main.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,24 @@ | ||||
| #include <stdio.h> | ||||
| #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; | ||||
| } | ||||
							
								
								
									
										20
									
								
								src/myAlphabet.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								src/myAlphabet.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,20 @@ | ||||
| #include <ctype.h> | ||||
| #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; | ||||
| } | ||||
							
								
								
									
										9
									
								
								src/myAlphabet.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								src/myAlphabet.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,9 @@ | ||||
| #ifndef MY_ALPHABET_H_ | ||||
| #define MY_ALPHABET_H_ | ||||
| 
 | ||||
| #include "myString.h" | ||||
| 
 | ||||
| char isVovel(int c); | ||||
| char areVovelMore(MyString str); | ||||
| 
 | ||||
| #endif | ||||
							
								
								
									
										37
									
								
								src/myString.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								src/myString.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,37 @@ | ||||
| #include <stdlib.h> | ||||
| #include <stdio.h> | ||||
| #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); | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										15
									
								
								src/myString.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								src/myString.h
									
									
									
									
									
										Normal file
									
								
							| @ -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 | ||||
							
								
								
									
										41
									
								
								src/scanFile.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								src/scanFile.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,41 @@ | ||||
| #include <stdio.h> | ||||
| #include <ctype.h> | ||||
| #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); | ||||
| } | ||||
							
								
								
									
										11
									
								
								src/scanFile.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								src/scanFile.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,11 @@ | ||||
| #ifndef SCANFILE_H_ | ||||
| #define SCANFILE_H_ | ||||
| 
 | ||||
| #include <stdio.h> | ||||
| #include "myString.h" | ||||
| 
 | ||||
| void processFile(FILE* in, FILE* out); | ||||
| void scanString(MyString* dst, FILE* src); | ||||
| void processString(FILE* out, MyString str); | ||||
| 
 | ||||
| #endif | ||||
							
								
								
									
										2
									
								
								test_files/test1_in
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								test_files/test1_in
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,2 @@ | ||||
| bbad, sdiv | ||||
| aaagh yd | ||||
							
								
								
									
										3
									
								
								test_files/test1_out
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								test_files/test1_out
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,3 @@ | ||||
| bdsv | ||||
| ay | ||||
| 
 | ||||
							
								
								
									
										2
									
								
								test_files/test2_in
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								test_files/test2_in
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,2 @@ | ||||
| Shall I compare thee to a summer’s day? | ||||
| Thou art more lovely and more temperate… | ||||
							
								
								
									
										3
									
								
								test_files/test2_out
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								test_files/test2_out
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,3 @@ | ||||
| shlcmprtd | ||||
| thrmlvndp | ||||
| 
 | ||||
							
								
								
									
										3
									
								
								test_files/test3_in
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								test_files/test3_in
									
									
									
									
									
										Normal file
									
								
							| @ -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 | ||||
							
								
								
									
										4
									
								
								test_files/test3_out
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								test_files/test3_out
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,4 @@ | ||||
| thqckbrwnfxjmpsvldg | ||||
| ckdwslvmbgphnxfqrt | ||||
| thfvbxngwrdsjmpqckl | ||||
| 
 | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user