diff --git a/calc.c b/calc.c old mode 100644 new mode 100755 index 85f1466..1b0d10f --- a/calc.c +++ b/calc.c @@ -5,28 +5,29 @@ int main(){ FILE *fp = NULL; int operand1, operand2; char operator = ' '; - int result, line = 0; + double result, line = 0; fp = fopen("read.txt","r"); if(fp!=NULL){ - fscanf(fp, "%d", &line); + my_fscanf(fp, "%d", &line); - for(int i=0; i +#include + +void my_fscanf(FILE* fp, const char* format, ...){ + va_list list; //가변 인자 목록 포인터 + int dtemp=0; + char temp; + char ctemp= ' '; + va_start(list, format); + + while(*format){ + if(*format == '%'){ + format++; + switch(*format){ + case 'd': + while(isspace(temp)){ + //empty + } + while(isdigit(temp)){ + dtemp = temp; + temp = getc(fp); + } + dtemp = va_arg(list, int); + dtemp = 0; + format++; + break; + + case 'c': + while(isspace(temp)){ + //empty + } + while(isgraph(temp)){ + ctemp =temp; + temp = getc(fp); + } + ctemp = va_arg(list, char); + format++; + break; + default break; + } + } + else if(isspace(*format)){ + format++; + } + } + va_end(list); +} + + + + diff --git a/my_fscanf.h b/my_fscanf.h new file mode 100755 index 0000000..9ed3568 --- /dev/null +++ b/my_fscanf.h @@ -0,0 +1,7 @@ +#ifdef MY_FSCANF_H +#define MY_FSCANF_H +#include + +void my_fscanf(FILE *fp, const char *format,...); + +#endif /* !MY_FSCANF_H */ diff --git a/operators.c b/operators.c old mode 100644 new mode 100755 index d51cb3e..34999cd --- a/operators.c +++ b/operators.c @@ -1,16 +1,16 @@ #include "operators.h" -int add(int op1, int op2) { +double add(double op1, double op2) { return op1+op2; } -int minus(int op1, int op2) { +double minus(double op1, double op2) { return op1-op2; } -int mul(int op1, int op2) { +double mul(double op1, double op2) { return op1*op2; } -int div(int op1, int op2) { - return op1%op2; +double div(double op1, double op2) { + return op1/op2; } diff --git a/operators.h b/operators.h old mode 100644 new mode 100755 index bd08f7d..0172ff3 --- a/operators.h +++ b/operators.h @@ -1,4 +1,4 @@ -int add(int op1, int op2); -int mul(int op1, int op2); -int div(int op1, int op2); -int minus(int op1, int op2); +double add(double op1, double op2); +double mul(double op1, double op2); +double div(double op1, double op2); +double minus(double op1, double op2);