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
Empty file modified calc
100755 → 100644
Empty file.
5 changes: 3 additions & 2 deletions calc.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <stdio.h>
#include "operators.h"
#include "my_fscanf.h"

int main(){
FILE *fp = NULL;
Expand All @@ -9,10 +10,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<line; i++) {
fscanf(fp, "%d %c %d",&operand1, &operator, &operand2);
my_fscanf(fp, "%d %c %d",&operand1, &operator, &operand2);
switch(operator) {
case '+':
result = add(operand1, operator);
Expand Down
Binary file modified calc.o
Binary file not shown.
20 changes: 20 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <stdio.h>
#include "operators.h"
#include "my_fscanf.h"
int main(void) { 
FILE* 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;
}
34 changes: 34 additions & 0 deletions my_fscanf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

#include "my_fscanf.h"
#include <stdarg.h>
#include <ctype.h>
void my_fscanf(FILE *fp, const char *format, ... ) {
va_list list;
va_start(list, format);
while(*format) {
if(*format == '%') {
format++;
switch(*format)
int* d;
char* cc;
int c;

case 'd':
while(isspace(c=getc(fp))){}
d = va_arg(list, int);
while (isdigit(c)) {
num = num*10+c-'0';
c = getc(fp);
}
*d = num;
break;
case 'c':
cc = va_arg(list, char*);
while (isspace(c = getc(fp))) {}
cc = getc(fp);
*cc = c;
break;
}
}
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 !MY_FSCANF_H