Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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.

35 changes: 0 additions & 35 deletions calc.c

This file was deleted.

21 changes: 21 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <stdio.h>
#include <string.h>
#include "my_fscanf.h"

int main(){
fp = fopen("points.txt","r");
char type[10];
double x,y;
int line;

if(fp!=NULL){
my_fscanf(fp, "%d", &line);
for(int i =0; i < line; i++){
my_fscanf(fp, "%s (%f,%f)",type, &x, &y);
if(strcmp(type, "point") == 0) {
printf("X: %f:, Y: %f\n", x, y);
}
}
}
return 0;
}
82 changes: 82 additions & 0 deletions my_fscanf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#include "my_fscanf.h"
#include <stdarg.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>

void my_fscanf(FILE *fp, const char *format, ...) {
va_list list;
va_start(list, format);
while(*format) {
if(*format == '%'){
format++;
switch(*format){
case 'd':{
int c = getc(fp);
int *s=va_arg(list, int*);

while(isspace(c)){

}
unsigned int num= 0;
while(isdight(c)){
*s = num * 10 + c -'0';
c=getc(fp);
}
while (isspace(c)){}
format++;
ungetc(c,fp);
break;
}
case 'c':{
char *ch = va_arg(list,char*);
char c=getc(fp);
while (isspace(c)){}
*ch = c;
format++;
break;
}
case 's':{
char *sp = va_arg(list, char*);
int s = 1;
while(isspace(c=getc(fp))){}

while (!isspace(c=getc(fp))){
sp[s]=c;
s++;
}
sp[s]=0;
format++;
ungetc(c,fp);
break;
}
case 'f':{
double *f_p=va_arg(list, double*);
double di = 0.1;
double c=getc(fp);
while(isspace(c)){}
*f_p = 0;
while (isdigit(c)){
*f_p= *f_p * 10 + c - '0';
c= getc(fp);
}
if (c == '.'){
c = getc(fp);
while(isdigit(c)){
*f_p=*f_p + (c - '0') * di;
di = di* 0.1;
c=getc(fp);
}
}
format++;
ungetc(c,fp);
break;
}
else{
int c = getc(fp);
if(*format==c)
format++;
}
}
va_end(list);
}
7 changes: 7 additions & 0 deletions my_fscanf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef MY_FSCANF_H
#define MY_FSCANF_H
#include <stdio.h>

void my_fscanf(FILE *fp,const char *format, ...);

#endif
5 changes: 3 additions & 2 deletions operators.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ 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/(double)op2;
}


2 changes: 1 addition & 1 deletion operators.h
Original file line number Diff line number Diff line change
@@ -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);
5 changes: 5 additions & 0 deletions points.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
4
point (1.3,2.2)
point (2.5,3.0)
point (3.2,4.4)
point (1.0,5.9)
5 changes: 0 additions & 5 deletions read.txt

This file was deleted.