From 8dc794aaf439ad1285c89e95079ba54c2176b87a Mon Sep 17 00:00:00 2001 From: sand621 Date: Thu, 25 May 2017 17:58:30 +0900 Subject: [PATCH 1/2] init --- calc.c | 20 +++++++++++++------- calc.o | Bin 6608 -> 6872 bytes operators.c | 4 ++-- operators.h | 2 +- operators.o | Bin 3288 -> 3336 bytes 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/calc.c b/calc.c index 85f1466..754349b 100644 --- a/calc.c +++ b/calc.c @@ -5,28 +5,34 @@ int main(){ FILE *fp = NULL; int operand1, operand2; char operator = ' '; - int result, line = 0; + double result = 0; + int line=0; + int (*sp1) (int,int)=add; + int (*sp2) (int,int)=minus; + int (*sp3) (int,int)=mul; + double (*sp4) (int,int)=div; fp = fopen("read.txt","r"); if(fp!=NULL){ fscanf(fp, "%d", &line); - for(int i=0; i>dB}1 z;`(hiNjozqq@5kdS?B-{Eu5SrAGe(>Wyhwcr?5#jXUDwhCD*eoHaj*WJuN%tO9w|b z54oSm%az8xmF7oQP2ejJ!*eI_@I$aXGI@gELN3|fDY4T!x0?~$*8$dH zIUisRXU<8vOy6yrJC=JJwq4`@j*lw`AmulWg{9VK zlvj|}D+hP}R4?g`gu*k^Z>FK2di3$AnH+%c=~P-Qj!;>Ui@YuybbnAsh&7rdRL@sJ zVZKe#4QrUu75d}{+|SXi-mB10(KSX`s;)4AuBnpyrEEhyu=FKM5@_`b%+Rl66!-9QUV}v>@Wsk{(7>xTF)ETRIjDzdEOdVe+6AOql z!NL3DB_AN$bOdfz{b+Z%X_KejNu7-ANxKtD`YA$@Lcvu}@4%n>!8wIYHk;jQ^z|F} z3<`}-p~+<&d=me%M5q!T<&!QcOs8x?4KEmUu50kCq0tcT&a8`l4Nfzk&ZGsl@4{T3wEwu7mS8t zaem5vKCw~59_2fsc!bPD%k_!Z#@37P(;FS=aI@q-Pgr z_t^_0cgHK^ZPe9x-Uc7rD@Mt8v9%ii8R}}h6@BHmM2Po)2^;Vms3wS*um!eQMA{GU zT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E5VQ1Q?&D=2KH}AWA-N9^Pqu^!&Si(S1$pq_`<-(Xw~-yd>_SsHQ+Xi|7pO7 zDV~R~bYf(yMAAYMgvR=cBII^kUSGo=x50Lok2#O8;5zI_U3J`fda}(hYZbsIx;cIF zWgNbgU68e!pkGTbNj~;70d7h@Zbs1LBbt1Jo1N#NXM>M( M(D5{B`*7L*15rq*qW}N^ diff --git a/operators.c b/operators.c index d51cb3e..d39d0db 100644 --- a/operators.c +++ b/operators.c @@ -10,7 +10,7 @@ int mul(int op1, int op2) { return op1*op2; } -int div(int op1, int op2) { - return op1%op2; +double div(int op1, int op2) { + return (double)op1/op2; } diff --git a/operators.h b/operators.h index bd08f7d..e16bf60 100644 --- 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); +double div(int op1, int op2); int minus(int op1, int op2); diff --git a/operators.o b/operators.o index 71b996c467c636eea2a5466488a72a5e4c372d7d..9ce07fd3a544f18c8449939dcd00d4c9c830ab7b 100644 GIT binary patch delta 446 zcmca1*&#JSgVAH6W|U+a|N8@<__bXB02wEN4BsE0_~Q=79yXZRufP~Ral;u!rj*Pw z21Z^TMg}-gg0dLrfJ7(HWRzuN<6r>_PTtCxp`yaT&27ic%m?J_05KC-F$b805z&(s zIm8)VCucA@GI2ysUd0ruoRVLfl#|M!pOK%Ns$ZO#mttmQs2`qRlwDkqn4GGglbB>V zS(aIjH8(S_w0N==vl-Cb$@$E!f?&ru@(HvtIrFl`^00FN&6eJ*z*51;s5E&dYdT}= zWJWe|#_-9KZ1Ic}Cs(rh3+hAt!Uc2>ClCj0KFGG6kuiF*AdB$i9u5`8*^@VN*aOLr z9QK^Ep^i40Y{_ZPd4m zF_}w+NrQdzCN4Y9oluGCU>6~=(chTQf*w-y4)j>#K=B+w`zxnQy(k3FNpx*<71gHd9lW)x4i>z|q5YkzcJh&`-2agG9`-^9IVWZ6Ee2f_L9sTR@~Oy>XM$qf{a4!4ieLyBq!T4Ni+IQR%8)pbeUYp3qU_>=#N^b;I?QsD1DH)GcQCgIg6(qT z6KG>{=4A`uVdt0}$RWMif~A6yQFQV~)^y1RsAFJ`;sWwHfjDfkAzM6Sz~qT+{+oZW zZD0gCV Date: Thu, 25 May 2017 21:04:26 +0900 Subject: [PATCH 2/2] lab14 --- calc.c | 6 +++--- my_fscanf.c | 38 ++++++++++++++++++++++++++++++++++++++ my_fscanf.h | 7 +++++++ 3 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 my_fscanf.c create mode 100644 my_fscanf.h diff --git a/calc.c b/calc.c index 754349b..2a46f55 100644 --- a/calc.c +++ b/calc.c @@ -1,6 +1,6 @@ #include #include "operators.h" - +#include "my_fscanf.h" int main(){ FILE *fp = NULL; int operand1, operand2; @@ -14,10 +14,10 @@ int main(){ 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*d; + char *dc; + int c; + va_start(list,format); + while(*format){ + if(*format == '%'){ + format++; + switch(*format){ + case 'd': + d=va_arg(list,int*); + while(isspace(c=getc(fp))){} + unsigned int num =0; + while(isdigit(c)){ + num=num*10+c-'0'; + c=getc(fp); + } + *d=num; + break; + case 'c': + dc=va_arg(list,char*); + c=getc(fp); + *dc=c; + break; + case ' ': + break; + }; + } + else + format++; + } + va_end(list); + printf("\n"); +} diff --git a/my_fscanf.h b/my_fscanf.h new file mode 100644 index 0000000..437ce8e --- /dev/null +++ b/my_fscanf.h @@ -0,0 +1,7 @@ +#ifndef MY_FSCANF_H +#define MY_FSCANF_H +#include + +void my_fscanf(FILE *fp, const char *format,...); + +#endif