diff --git a/.gitinore b/.gitinore new file mode 100644 index 0000000..2490a4d --- /dev/null +++ b/.gitinore @@ -0,0 +1,2 @@ +*.o +/calc diff --git a/README.md b/README.md deleted file mode 100644 index 68b2d37..0000000 --- a/README.md +++ /dev/null @@ -1,16 +0,0 @@ -# Simple Calculator - -This is a buggy application that will be used for Lab5 of 'Introduction to Open Source Software Development.' - - - Fork the project. - - Create a topic branch from master. - - The branch name must be your student id. (e.g. 201624000) - - Make some commits to improve the project. - - Fix the well-knwon bugs. - - Remove object and binary files. - - Add .gitignore file - - Push this branch to your GitHub project. - - Open a Pull Request on GitHub. - - The Pull Request must be submitted to master branch of Classroom-IOSSD/SimpleCalculator! - - Capture the Pull Request and upload it to PLMS. - diff --git a/cal.c b/cal.c new file mode 100755 index 0000000..a0a4831 --- /dev/null +++ b/cal.c @@ -0,0 +1,23 @@ +#include +#include +#include "my_fscanf.h" + +int main() { + FILE* fp = fopen("points.txt", "r"); + char type[10]; + double x, y; + int line; + int i; + if (fp != NULL) + { + my_fscanf(fp, "%d\r\n", &line); + for (i = 0; i < line; i++) { + my_fscanf(fp, "%s (%f,%f)\r\n", type, &x, &y); + if (strcmp(type, "point") == 0) + { + printf("X: %f:, Y: %f\r\n", x, y); + } + } + } + return 0; +} diff --git a/calc b/calc index 023ec18..06d03dc 100755 Binary files a/calc and b/calc differ diff --git a/calc.c b/calc.c deleted file mode 100644 index 85f1466..0000000 --- a/calc.c +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include "operators.h" - -int main(){ - FILE *fp = NULL; - int operand1, operand2; - char operator = ' '; - int result, line = 0; - - fp = fopen("read.txt","r"); - if(fp!=NULL){ - fscanf(fp, "%d", &line); - - for(int i=0; i +#include +#include +#include + +void my_fscanf(FILE *fp, const char* format, ...) { + + va_list list; + va_start(list, format); + int c; + void* pVal; + + while (*format) { + if (*format == '%') { + format++; + switch (*format) { + case 'd': + c = getc(fp); + pVal = va_arg(list, int*); + *(int*)pVal = 0; + while (isdigit(c)) + { + *(int*)pVal = *(int*)pVal * 10 + (c - '0'); + c = getc(fp); + } + ungetc(c, fp); + break; + case 'c': + pVal = va_arg(list, char*); + c = getc(fp); + *(char*)pVal = c; + break; + case 's': + pVal = va_arg(list, char*); + ((char*)pVal)[0] = 0; + c = getc(fp); + while (!isspace(c)) + { + strncat((char*)pVal, &c , 1); + c = getc(fp); + } + ungetc(c, fp); + break; + case 'f':{ + pVal = va_arg(list, float*); + c = getc(fp); + *(double*)pVal = 0; + while (!isspace(c)) + { + if (c == '.') + { + c = getc(fp); + break; + } + *(double*)pVal = *(double*)pVal * 10 + (c - '0'); + c = getc(fp); + } + int n = 1; + while (!isspace(c) && isdigit(c)) + { + *(double*)pVal = *(double*)pVal + (c - '0') *0.1 *n; + c = getc(fp); + n++; + } + ungetc(c, fp); + break; + } + } + + } + else + c = getc(fp); + format++; + } + + va_end(list); + +} diff --git a/my_fscanf.h b/my_fscanf.h new file mode 100755 index 0000000..e89d55b --- /dev/null +++ b/my_fscanf.h @@ -0,0 +1,6 @@ +#pragma once +#ifndef MY_FSCANF_H +#define MY_FSCANF_H +#include +void my_fscanf(FILE *fp, const char *format, ...); +#endif \ No newline at end of file diff --git a/operators.c b/operators.c deleted file mode 100644 index d51cb3e..0000000 --- a/operators.c +++ /dev/null @@ -1,16 +0,0 @@ -#include "operators.h" - -int add(int op1, int op2) { - return op1+op2; -} -int minus(int op1, int op2) { - return op1-op2; -} -int mul(int op1, int op2) { - return op1*op2; -} - -int div(int op1, int op2) { - return op1%op2; -} - diff --git a/operators.h b/operators.h deleted file mode 100644 index bd08f7d..0000000 --- a/operators.h +++ /dev/null @@ -1,4 +0,0 @@ -int add(int op1, int op2); -int mul(int op1, int op2); -int div(int op1, int op2); -int minus(int op1, int op2); diff --git a/operators.o b/operators.o deleted file mode 100644 index 71b996c..0000000 Binary files a/operators.o and /dev/null differ diff --git a/points.txt b/points.txt new file mode 100755 index 0000000..0b3538c --- /dev/null +++ b/points.txt @@ -0,0 +1,6 @@ +4 +point (1.3,2.2) +point (2.5,3.0) +point (3.2,4.4) +point (1.0,5.9) + \ No newline at end of file diff --git a/read.txt b/read.txt deleted file mode 100644 index 3e2bf01..0000000 --- a/read.txt +++ /dev/null @@ -1,5 +0,0 @@ -5 -123 + 456 -234 * 234 -143 - 111 -987 / 132