diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..fadb812 --- /dev/null +++ b/.clang-format @@ -0,0 +1,6 @@ +UseTab: Never +IndentWidth: 4 +BreakBeforeBraces: Allman +AllowShortIfStatementsOnASingleLine: Never +IndentCaseLabels: false +ColumnLimit: 0 \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index ee1804d..2b657d7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,11 @@ { - "code-runner.executorMap":{ - "c": "cd $dir && gcc $fileName -Wall -Wextra -lm -o $fileNameWithoutExt && $dir$fileNameWithoutExt" + "code-runner.executorMap": { + "c": "cd $dir && gcc $fileName -Wall -Wextra -Wsign-conversion -Werror -Wfloat-equal -Wundef -Wshadow -Wpointer-arith -Wcast-align -Wstrict-prototypes -Wwrite-strings -Wcast-qual -Wunreachable-code -lm -o $fileNameWithoutExt && $dir$fileNameWithoutExt" + }, + "code-runner.ignoreSelection": true, + "files.associations": { + "safeinput.h": "c", + "safeinput_th.h": "c", + "safeinput_jp.h": "c" } } \ No newline at end of file diff --git a/README.md b/README.md index 0d828e7..a65f7bc 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ ## Program's Features +### Vector Calculation + * Add Vectors * Multiply Vector with scalar and vector @@ -14,11 +16,25 @@ * Find area of parrallelogram under two vectors +### Extra Feature that help visualizing + * Import Vector Data from and Export to Files * Set Number Precision (Number of digits after decimal point) -* Support 3 Languages: English, Thai, Japanese +### Very Good Memory Management + + There is almost no memory leak in this program from testing so far. + +* Tested using valgrind, however, some very small leaks are possible in rare case. + +* Only applies on English Version + +### Multilingual + +* Support 3 Languages: English, Thai and Japanese + + __Note__: In Thai and Japanese Version, Import/Export Vector and setting Number Precision is unstable. Please avoid using them. ## How to Run Program @@ -26,6 +42,14 @@ To use import/export function, VectorSave Folder must be in the same directory. +## Sample Vector Data to start with + + I've already put some sample vector data you can play with! + + These are generated using ```numpy```. + + Note: Use Import Vector Function to import them, but please avoid using them in TH,JP Version as it is unstable. + ## Compatibility Support both Windows and UNIX OS. @@ -40,7 +64,7 @@ Note : ```-lm``` (Math Library) must be manually attached when compiling in UNIX Version used to present to Teacher (Semester 1) : v1.3.0 - Current Release : v3.2 + Current Release : v3.3 ## Credits @@ -76,16 +100,22 @@ Note : ```-lm``` (Math Library) must be manually attached when compiling in UNIX Subject : 「การเขียนโปรแกรม 2 (ง30222)」 Triam Udom Suksa School (2020/2) - * 総制作 : @Leomotors + * 制作監督 : @Leomotors + + * Helper・Reviewer : @Teproanyx + + * Honorable Mention : Stack Overflow - * Honor Helper : Stack Overflow +### Special Thanks - * Reviewer・Tester : @Teproanyx + This Project uses Safe Input Module by @Teproanyx ## Program Version History ### Version 3 (Latest Version) + **2021-03-03** Present Ready Update (3.3): Fixed many bugs. Program should be stable now + **2021-03-01** Release 3.2: Seperate File (SafeInput.h) and Fatal Bug Fixes **2021-02-24** February Improvement Update (3.1): Upgrade to Double, Fix Mem Leak diff --git a/SafeInput.h b/SafeInput/SafeInput.h similarity index 90% rename from SafeInput.h rename to SafeInput/SafeInput.h index a6d9d8a..8df8235 100644 --- a/SafeInput.h +++ b/SafeInput/SafeInput.h @@ -4,6 +4,9 @@ * * Customed for this Vector Calculator: @Leomotors */ +#ifndef TEPROANYX_SAFE_INPUT +#define TEPROANYX_SAFE_INPUT + #include #include #include @@ -92,7 +95,7 @@ char *getString(const char *prompt) { size_t size = INITIAL_BUFFER; printf("%s", prompt); - char *buffer = (char *)malloc((size + 1) * sizeof(*buffer)); + char *buffer = malloc((size + 1) * sizeof(*buffer)); memoryError(buffer); if (fgets(buffer, size + 1, stdin) == NULL) { @@ -102,7 +105,7 @@ char *getString(const char *prompt) } while (buffer[strlen(buffer) - 1] != '\n') { - char *subBuffer = (char *)malloc((size + 1) * sizeof(*subBuffer)); + char *subBuffer = malloc((size + 1) * sizeof(*subBuffer)); memoryError(subBuffer); if (fgets(subBuffer, size + 1, stdin) == NULL) @@ -114,14 +117,14 @@ char *getString(const char *prompt) } size *= 2; - buffer = (char *)realloc(buffer, size + 1); + buffer = realloc(buffer, size + 1); memoryError(buffer); strncat(buffer, subBuffer, size / 2); free(subBuffer); } buffer[strlen(buffer) - 1] = '\0'; - buffer = (char *)realloc(buffer, strlen(buffer) + 1); + buffer = realloc(buffer, strlen(buffer) + 1); memoryError(buffer); return buffer; } @@ -134,3 +137,5 @@ void memoryError(const void *pointer) exit(EXIT_FAILURE); } } + +#endif diff --git a/SafeInput-wchar.h b/SafeInput/SafeInput_JP.h similarity index 67% rename from SafeInput-wchar.h rename to SafeInput/SafeInput_JP.h index 65f7957..3b0a667 100644 --- a/SafeInput-wchar.h +++ b/SafeInput/SafeInput_JP.h @@ -1,9 +1,14 @@ /** - * * Safe Input Module wchar_t as prompt version + * * Safe Input Module Japanese Version + * ! Translation might not be 100% correct. Author is just at N5. + * ! 翻訳が全部正しくない可能性があります。 作者はただN5です。 * * Original Work: @Teproanyx * * Customed for this Vector Calculator: @Leomotors */ +#ifndef TEPROANYX_SAFE_INPUT +#define TEPROANYX_SAFE_INPUT + #include #include #include @@ -30,7 +35,7 @@ long getLong(const wchar_t *prompt) if (buffer[0] == '\0') { free(buffer); - printf("Input error, please try again!\n"); + wprintf(L"入力エラー もう一度やり直してください。\n"); return getLong(prompt); } @@ -42,7 +47,7 @@ long getLong(const wchar_t *prompt) { free(buffer); fprintf(stderr, "Value conversion error\n"); - printf("Input error, please try again!\n"); + wprintf(L"入力エラー もう一度やり直してください。\n"); return getLong(prompt); } @@ -56,7 +61,7 @@ int getInt(const wchar_t *prompt) long n = getLong(prompt); if (n > INT_MAX || n < INT_MIN) { - printf("Input error, please try again!\n"); + wprintf(L"入力エラー もう一度やり直してください。\n"); return getInt(prompt); } return (int)n; @@ -68,7 +73,7 @@ double getDouble(const wchar_t *prompt) if (buffer[0] == '\0') { free(buffer); - printf("Input error, please try again!\n"); + wprintf(L"入力エラー もう一度やり直してください。\n"); return getLong(prompt); } @@ -80,7 +85,7 @@ double getDouble(const wchar_t *prompt) { free(buffer); fprintf(stderr, "Value conversion error\n"); - printf("Input error, please try again!\n"); + wprintf(L"入力エラー もう一度やり直してください。\n"); return getDouble(prompt); } @@ -93,36 +98,36 @@ char *getString(const wchar_t *prompt) { size_t size = INITIAL_BUFFER; wprintf(L"%s", prompt); - char *buffer = (char *)malloc((size + 1) * sizeof(*buffer)); + char *buffer = malloc((size + 1) * sizeof(*buffer)); memoryError(buffer); if (fgets(buffer, size + 1, stdin) == NULL) { free(buffer); - printf("Error, try again!\n"); + wprintf(L"エラー、もう一度やり直してください。\n"); return getString(prompt); } while (buffer[strlen(buffer) - 1] != '\n') { - char *subBuffer = (char *)malloc((size + 1) * sizeof(*subBuffer)); + char *subBuffer = malloc((size + 1) * sizeof(*subBuffer)); memoryError(subBuffer); if (fgets(subBuffer, size + 1, stdin) == NULL) { free(buffer); free(subBuffer); - printf("Read Error(WTF HOW), try again MTFKER!\n"); + wprintf(L"Read Error(WTF HOW), try again MTFKER!\n"); return getString(prompt); } size *= 2; - buffer = (char *)realloc(buffer, size + 1); + buffer = realloc(buffer, size + 1); memoryError(buffer); strncat(buffer, subBuffer, size / 2); free(subBuffer); } buffer[strlen(buffer) - 1] = '\0'; - buffer = (char *)realloc(buffer, strlen(buffer) + 1); + buffer = realloc(buffer, strlen(buffer) + 1); memoryError(buffer); return buffer; } @@ -131,7 +136,9 @@ void memoryError(const void *pointer) { if (pointer == NULL) { - printf("Not enough RAM. Terminating program...\n"); + wprintf(L"RAMは十分ではありません プログラムを終了しています...\n"); exit(EXIT_FAILURE); } } + +#endif diff --git a/SafeInput/SafeInput_TH.h b/SafeInput/SafeInput_TH.h new file mode 100644 index 0000000..85bcb1c --- /dev/null +++ b/SafeInput/SafeInput_TH.h @@ -0,0 +1,142 @@ +/** + * * Safe Input Module Thai Version + * * Original Work: @Teproanyx + * * Customed for this Vector Calculator: @Leomotors + */ + +#ifndef TEPROANYX_SAFE_INPUT +#define TEPROANYX_SAFE_INPUT + +#include +#include +#include +#include +#include +#include +#include +#include +#define INITIAL_BUFFER 8 + +// * Function Prototype (Declaration) * // + +long long getlong(const wchar_t *); +int getInt(const wchar_t *); +double getDouble(const wchar_t *); +char *getString(const wchar_t *); +void memoryError(const void *); + +// * Function Definition * // + +long getLong(const wchar_t *prompt) +{ + char *buffer = getString(prompt); + if (buffer[0] == '\0') + { + free(buffer); + wprintf(L"การป้อนข้อมูลผิดพลาด โปรดลองใหม่อีกครั้ง\n"); + return getLong(prompt); + } + + char *end = NULL; + errno = 0; + + long n = strtol(buffer, &end, 10); + if (errno || *end != '\0') + { + free(buffer); + fprintf(stderr, "Value conversion error\n"); + wprintf(L"การป้อนข้อมูลผิดพลาด โปรดลองใหม่อีกครั้ง\n"); + return getLong(prompt); + } + + free(buffer); + + return n; +} + +int getInt(const wchar_t *prompt) +{ + long n = getLong(prompt); + if (n > INT_MAX || n < INT_MIN) + { + wprintf(L"การป้อนข้อมูลผิดพลาด โปรดลองใหม่อีกครั้ง\n"); + return getInt(prompt); + } + return (int)n; +} + +double getDouble(const wchar_t *prompt) +{ + char *buffer = getString(prompt); + if (buffer[0] == '\0') + { + free(buffer); + wprintf(L"การป้อนข้อมูลผิดพลาด โปรดลองใหม่อีกครั้ง\n"); + return getLong(prompt); + } + + char *end = NULL; + errno = 0; + + double n = strtod(buffer, &end); + if (errno || *end != '\0') + { + free(buffer); + fprintf(stderr, "Value conversion error\n"); + wprintf(L"การป้อนข้อมูลผิดพลาด โปรดลองใหม่อีกครั้ง\n"); + return getDouble(prompt); + } + + free(buffer); + + return n; +} + +char *getString(const wchar_t *prompt) +{ + size_t size = INITIAL_BUFFER; + wprintf(L"%s", prompt); + char *buffer = malloc((size + 1) * sizeof(*buffer)); + memoryError(buffer); + if (fgets(buffer, size + 1, stdin) == NULL) + { + free(buffer); + wprintf(L"Error, try again!\n"); + return getString(prompt); + } + while (buffer[strlen(buffer) - 1] != '\n') + { + char *subBuffer = malloc((size + 1) * sizeof(*subBuffer)); + memoryError(subBuffer); + + if (fgets(subBuffer, size + 1, stdin) == NULL) + { + free(buffer); + free(subBuffer); + wprintf(L"Read Error(WTF HOW), try again MTFKER!\n"); + return getString(prompt); + } + + size *= 2; + buffer = realloc(buffer, size + 1); + memoryError(buffer); + + strncat(buffer, subBuffer, size / 2); + free(subBuffer); + } + buffer[strlen(buffer) - 1] = '\0'; + buffer = realloc(buffer, strlen(buffer) + 1); + memoryError(buffer); + return buffer; +} + +void memoryError(const void *pointer) +{ + if (pointer == NULL) + { + wprintf(L"RAM ไม่เพียงพอ กำลังปิดโปรแกรม...\n"); + exit(EXIT_FAILURE); + } +} + +#endif diff --git a/VectorCalc.c b/VectorCalc.c index bec1cf6..d465df6 100644 --- a/VectorCalc.c +++ b/VectorCalc.c @@ -9,7 +9,7 @@ #include #include -#include "SafeInput.h" +#include "SafeInput/SafeInput.h" #define i 0 #define j 1 @@ -38,6 +38,7 @@ void ShowAllVectors(void); void saveVectorToSlot(double *); bool isVector(int); bool deleteAllVectors(void); +void freeAllVectors(void); // * Import and Export void importVector(void); @@ -61,11 +62,14 @@ int main(void) while (true) { cls(); - printf("=====|Vector Calculator V3.2|=====\n\n"); + printf("=====|Vector Calculator V3.3|=====\n\n"); ShowAllVectors(); printMainMenu(); if (!programCore()) + { + freeAllVectors(); return 0; + } } } @@ -180,7 +184,7 @@ void vectorOperation(void) printf("\n"); break; case 2: - temp = getInt("Enter scalar to multiply with: "); + temp = getDouble("Enter scalar to multiply with: "); saveVectorToSlot((scalarMult(vector[u], temp))); break; case 3: @@ -439,6 +443,15 @@ bool deleteAllVectors(void) return true; } +void freeAllVectors(void) +{ + for (int lc = 0; lc < VECTOR_ARRAY_SIZE; lc++) + { + if (vector[lc] != NULL) + free(vector[lc]); + } +} + // * Import and Export void importVector(void) { @@ -495,9 +508,9 @@ void exportVector(void) free(tmp); if ((outputFile = fopen(filename, "r")) != NULL) { + fclose(outputFile); if (!getConfirmation("File already exists, Overwrite? [Y/N]: ")) { - fclose(outputFile); return; } } @@ -508,7 +521,6 @@ void exportVector(void) if (vector[c] != NULL) fprintf(outputFile, "%d %lf %lf %lf\n", c, vector[c][i], vector[c][j], vector[c][k]); } - free(tmp); fclose(outputFile); } diff --git a/VectorCalc_JP.c b/VectorCalc_JP.c index 6e0a9d3..bd15e7d 100644 --- a/VectorCalc_JP.c +++ b/VectorCalc_JP.c @@ -17,7 +17,7 @@ #include #include -#include "SafeInput-wchar.h" +#include "SafeInput/SafeInput_JP.h" #define i 0 #define j 1 @@ -46,6 +46,7 @@ void ShowAllVectors(void); void saveVectorToSlot(double *); bool isVector(int); bool deleteAllVectors(void); +void freeAllVectors(void); // * Import and Export void importVector(void); @@ -67,11 +68,14 @@ int main(void) while (true) { cls(); - wprintf(L"=====|Vector Calculator V3.2 Japanese Version|=====\n\n"); + wprintf(L"=====|Vector Calculator V3.3 Japanese Version|=====\n\n"); ShowAllVectors(); printMainMenu(); if (!programCore()) + { + freeAllVectors(); return 0; + } } } @@ -81,7 +85,7 @@ void printMainMenu(void) wprintf(L"\n下の機能を選んでください。\n"); wprintf(L"[1] 新ベクトルを入力する\n"); wprintf(L"[2] ベクトルについて計算\n"); - wprintf(L"[3] インポート・エクスポートベクトル\n"); + wprintf(L"[3] Lab: インポート・エクスポートベクトル\n"); wprintf(L"[4] すべてのベクトルを削除する\n"); wprintf(L"[5] 設定\n"); wprintf(L"[0] プログラムを終了する\n"); @@ -187,7 +191,7 @@ void vectorOperation(void) wprintf(L"\n"); break; case 2: - temp = getInt(L"持って掛けるスカラー量を入力してください: "); + temp = getDouble(L"持って掛けるスカラー量を入力してください: "); saveVectorToSlot((scalarMult(vector[u], temp))); break; case 3: @@ -222,7 +226,7 @@ void settingsMenu(void) int choice; wprintf(L"\n=====|設定|=====\n\n"); wprintf(L"[1] 画面の色を変化する\n"); - wprintf(L"[2] 数値精度を設定する\n"); + wprintf(L"[2] Lab: 数値精度を設定する\n"); wprintf(L"[0] 戻る\n"); choice = getInt(L"選ぶ: "); switch (choice) @@ -233,6 +237,10 @@ void settingsMenu(void) case 2: while (true) { + if (!getConfirmation(L"警告: この機能は不安定で、エラー可能性があります。継続しますか? [Y/N]: ")) + { + return; + } numberPrecision = getInt(L"小数点以下の桁数 : "); if (numberPrecision >= 0 && numberPrecision <= 6) break; @@ -256,6 +264,7 @@ void fileMenu(void) { int choice; wprintf(L"\n=====|ファイルメニュー|=====\n\n"); + wprintf(L"警告: この機能は不安定で、エラー可能性があります。\n"); wprintf(L"[1] インポート・ベクトル\n"); wprintf(L"[2] エクスポート・ベクトル\n"); wprintf(L"[0] 戻る\n"); @@ -377,14 +386,11 @@ wchar_t *printvec(double *u) void ShowAllVectors(void) { - wchar_t *tmp; for (int m = 0; m < VECTOR_ARRAY_SIZE; m++) { if (vector[m] != NULL) { - tmp = printvec(vector[m]); - wprintf(L"ベクトル #%d : %s\n", m, tmp); - free(tmp); + wprintf(L"ベクトル #%d : %s\n", m, printvec(vector[m])); } } } @@ -392,9 +398,7 @@ void ShowAllVectors(void) void saveVectorToSlot(double *u) { int w; - wchar_t *tmp = printvec(u); - wprintf(L"結果のベクトルは %s\n", tmp); - free(tmp); + wprintf(L"結果のベクトルは %s\n", printvec(u)); if (!getConfirmation(L"ベクトルを保存しますか? [Y/N]: ")) { free(u); @@ -447,6 +451,15 @@ bool deleteAllVectors(void) return true; } +void freeAllVectors(void) +{ + for (int lc = 0; lc < VECTOR_ARRAY_SIZE; lc++) + { + if (vector[lc] != NULL) + free(vector[lc]); + } +} + // * Import and Export void importVector(void) { @@ -503,9 +516,9 @@ void exportVector(void) free(tmp); if ((outputFile = fopen(filename, "r")) != NULL) { + fclose(outputFile); if (!getConfirmation(L"このファイルはすでに存在します。 上書きしますか? [Y/N]: ")) { - fclose(outputFile); return; } } @@ -516,7 +529,6 @@ void exportVector(void) if (vector[c] != NULL) fprintf(outputFile, "%d %lf %lf %lf\n", c, vector[c][i], vector[c][j], vector[c][k]); } - free(tmp); fclose(outputFile); } diff --git a/VectorCalc_TH.c b/VectorCalc_TH.c index 17c0aa0..ee74598 100644 --- a/VectorCalc_TH.c +++ b/VectorCalc_TH.c @@ -15,7 +15,7 @@ #include #include -#include "SafeInput-wchar.h" +#include "SafeInput/SafeInput_TH.h" #define i 0 #define j 1 @@ -44,6 +44,7 @@ void ShowAllVectors(void); void saveVectorToSlot(double *); bool isVector(int); bool deleteAllVectors(void); +void freeAllVectors(void); // * Import and Export void importVector(void); @@ -65,11 +66,14 @@ int main(void) while (true) { cls(); - wprintf(L"=====|Vector Calculator V3.2 Thai Version|=====\n\n"); + wprintf(L"=====|Vector Calculator V3.3 Thai Version|=====\n\n"); ShowAllVectors(); printMainMenu(); if (!programCore()) + { + freeAllVectors(); return 0; + } } } @@ -79,7 +83,7 @@ void printMainMenu(void) wprintf(L"\nโปรดเลือกฟังก์ชันจากข้างล่างนี้\n"); wprintf(L"[1] ป้อนเวกเตอร์ใหม่\n"); wprintf(L"[2] คำนวณเกี่ยวกับเวกเตอร์\n"); - wprintf(L"[3] นำเข้าและส่งออกเวกเตอร์\n"); + wprintf(L"[3] Lab: นำเข้าและส่งออกเวกเตอร์\n"); wprintf(L"[4] ลบเวกเตอร์ทั้งหมด\n"); wprintf(L"[5] การตั้งค่า\n"); wprintf(L"[0] ออกจากโปรแกรม\n"); @@ -184,7 +188,7 @@ void vectorOperation(void) wprintf(L"\n"); break; case 2: - temp = getInt(L"ใส่ค่าสเกลาร์ที่จะนำไปคูณ: "); + temp = getDouble(L"ใส่ค่าสเกลาร์ที่จะนำไปคูณ: "); saveVectorToSlot((scalarMult(vector[u], temp))); break; case 3: @@ -219,7 +223,7 @@ void settingsMenu(void) int choice; wprintf(L"\n=====|การตั้งค่า|=====\n\n"); wprintf(L"[1] เปลี่ยนสีหน้าจอ\n"); - wprintf(L"[2] เลือกความละเอียดของตัวเลข\n"); + wprintf(L"[2] Lab: เลือกความละเอียดของตัวเลข\n"); wprintf(L"[0] กลับ\n"); choice = getInt(L"ตัวเลือกที่เลือก: "); switch (choice) @@ -230,6 +234,10 @@ void settingsMenu(void) case 2: while (true) { + if(!getConfirmation(L"คำเตือน: ฟังก์ชันนี้ไม่เสถียรและอาจทำให้โปรแกรมค้างได้ ดำเนินการต่อ? [Y/N]: ")) + { + return; + } numberPrecision = getInt(L"จำนวนหลักหลังทศนิยม: "); if (numberPrecision >= 0 && numberPrecision <= 6) break; @@ -253,6 +261,7 @@ void fileMenu(void) { int choice; wprintf(L"\n=====|เมนูไฟล์|=====\n\n"); + wprintf(L"คำเตือน: ฟังก์ชันนี้ไม่เสถียรและอาจทำให้โปรแกรมค้างได้\n"); wprintf(L"[1] นำเข้าเวกเตอร์\n"); wprintf(L"[2] ส่งออกเวกเตอร์\n"); wprintf(L"[0] กลับ\n"); @@ -366,21 +375,16 @@ wchar_t *printvec(double *u) } // * Forcing '\0' to stop string from printing wstr[tstrlen] = '\0'; - free(format); - free(str); return wstr; } void ShowAllVectors(void) { - wchar_t *tmp; for (int m = 0; m < VECTOR_ARRAY_SIZE; m++) { if (vector[m] != NULL) { - tmp = printvec(vector[m]); - wprintf(L"เวกเตอร์ หมายเลข %d : %s\n", m, tmp); - free(tmp); + wprintf(L"เวกเตอร์ หมายเลข %d : %s\n", m, printvec(vector[m])); } } } @@ -388,9 +392,7 @@ void ShowAllVectors(void) void saveVectorToSlot(double *u) { int w; - wchar_t *tmp = printvec(u); - wprintf(L"เวกเตอร์ผลลัพธ์คือ %s\n", tmp); - free(tmp); + wprintf(L"เวกเตอร์ผลลัพธ์คือ %s\n", printvec(u)); if (!getConfirmation(L"ต้องการบันทึกเวกเตอร์หรือไม่? [Y/N]: ")) { free(u); @@ -443,6 +445,15 @@ bool deleteAllVectors(void) return true; } +void freeAllVectors(void) +{ + for (int lc = 0; lc < VECTOR_ARRAY_SIZE; lc++) + { + if (vector[lc] != NULL) + free(vector[lc]); + } +} + // * Import and Export void importVector(void) { @@ -499,9 +510,9 @@ void exportVector(void) free(tmp); if ((outputFile = fopen(filename, "r")) != NULL) { + fclose(outputFile); if (!getConfirmation(L"ไฟล์นี้มีอยู่แล้ว เขียนทับ? [Y/N]: ")) { - fclose(outputFile); return; } } @@ -512,7 +523,6 @@ void exportVector(void) if (vector[c] != NULL) fprintf(outputFile, "%d %lf %lf %lf\n", c, vector[c][i], vector[c][j], vector[c][k]); } - free(tmp); fclose(outputFile); } diff --git a/VectorSave/Data0.txt b/VectorSave/Data0.txt new file mode 100644 index 0000000..1607ed3 --- /dev/null +++ b/VectorSave/Data0.txt @@ -0,0 +1,11 @@ +0 0 0 0 +1 3 4 5 +2 5 6 7 +3 1 2 4 +4 5 1 9 +5 5 1 2 +6 -3 2 0 +7 1 -9 5 +8 -5 -3 -4 +9 -1 4 -2 +10 3 2 5 \ No newline at end of file diff --git a/VectorSave/Data1.txt b/VectorSave/Data1.txt index 1607ed3..c5474d6 100644 --- a/VectorSave/Data1.txt +++ b/VectorSave/Data1.txt @@ -1,11 +1,15 @@ -0 0 0 0 -1 3 4 5 -2 5 6 7 -3 1 2 4 -4 5 1 9 -5 5 1 2 -6 -3 2 0 -7 1 -9 5 -8 -5 -3 -4 -9 -1 4 -2 -10 3 2 5 \ No newline at end of file +0 99.332 93.641 34.608 +1 36.141 0.583 -63.554 +2 86.677 -39.405 23.261 +3 -60.036 80.595 28.393 +4 88.631 6.795 -21.977 +5 -48.548 -74.314 -62.998 +6 -20.603 -87.317 22.977 +7 26.794 -85.239 56.187 +8 -65.324 -73.975 49.631 +9 -40.374 79.199 60.675 +10 0.935 -81.437 -62.618 +11 -81.747 41.623 -12.839 +12 -70.467 96.488 91.490 +13 57.334 14.368 41.699 +14 -73.032 -62.768 87.051 \ No newline at end of file diff --git a/VectorSave/Data2.txt b/VectorSave/Data2.txt index 722b549..c1cf698 100644 --- a/VectorSave/Data2.txt +++ b/VectorSave/Data2.txt @@ -1,11 +1,15 @@ -0 0.000000 0.000000 0.000000 -1 3.000000 4.000000 5.000000 -2 5.000000 6.000000 7.000000 -3 1.000000 2.000000 4.000000 -4 5.000000 1.000000 9.000000 -5 5.000000 1.000000 2.000000 -6 -3.000000 2.000000 0.000000 -7 1.000000 -9.000000 5.000000 -8 -5.000000 -3.000000 -4.000000 -9 -1.000000 4.000000 -2.000000 -10 3.000000 2.000000 5.000000 +0 -21.932 -40.262 -21.130 +1 -73.863 -83.654 57.492 +2 75.690 45.040 -81.184 +3 -51.539 -39.966 -78.646 +4 -63.316 -74.593 -57.215 +5 56.525 12.497 -78.899 +6 1.701 68.514 51.192 +7 -59.872 64.103 59.436 +8 75.968 -22.968 45.928 +9 -31.875 85.848 -47.337 +10 -12.338 1.392 -44.079 +11 48.159 -88.411 -25.738 +12 18.610 -73.487 -42.981 +13 -78.997 7.927 63.917 +14 -37.649 -98.462 97.400 \ No newline at end of file diff --git a/VectorSave/Data3.txt b/VectorSave/Data3.txt index c007c00..e267c08 100644 --- a/VectorSave/Data3.txt +++ b/VectorSave/Data3.txt @@ -1,5 +1,15 @@ -0 5 6 7 -1 2 3 4 -2 8 9 0 -3 10 11 21 -4 29 1 93 +0 43.4544 7.9190 -80.2831 +1 4.4897 -31.0335 -56.4951 +2 -57.9346 85.6819 -15.1778 +3 44.1331 54.7878 27.5071 +4 -99.9060 29.5024 38.3727 +5 52.8616 -74.4142 23.7594 +6 29.4211 -1.5573 -45.5659 +7 -28.1238 92.5853 -33.4357 +8 53.8767 -54.8586 -49.8934 +9 3.0729 48.4579 22.7302 +10 -50.3268 83.8453 -5.6935 +11 53.9872 -50.0624 -69.3693 +12 95.1284 -7.3761 56.9119 +13 54.4445 -26.8349 -31.9935 +14 48.4963 2.4828 -76.8858 \ No newline at end of file diff --git a/VectorSave/Data4.txt b/VectorSave/Data4.txt index 4efb902..d5ebf61 100644 --- a/VectorSave/Data4.txt +++ b/VectorSave/Data4.txt @@ -1,6 +1,15 @@ -0 5.000000 6.000000 7.000000 -1 2.000000 3.000000 4.000000 -2 837.000000 -744.000000 -253.000000 -3 10.000000 11.000000 21.000000 -4 15.000000 17.000000 28.000000 -5 9.000000 20.000000 2.000000 +0 34.434927 49.334712 33.795367 +1 -55.382226 71.053610 -32.984136 +2 -88.907807 68.849260 65.443037 +3 -45.068803 -51.373909 -88.847740 +4 -78.751739 -66.701568 95.235849 +5 71.246539 91.780275 97.608392 +6 -48.981635 -46.215974 56.646003 +7 0.716533 -42.428457 -12.809766 +8 64.281283 97.652050 -10.255882 +9 58.152714 18.041451 -93.579957 +10 -61.426656 73.623518 -89.452636 +11 -91.556438 91.095750 88.259268 +12 -38.278976 55.926798 -0.427501 +13 57.754220 -34.637380 -96.054396 +14 16.116748 88.016583 -47.592692 \ No newline at end of file