-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
567696b
commit 79006b4
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
int main(int argc, char *argv[]) { | ||
// create a buffer that can hold | ||
// up to 255 characters | ||
char buf[]; | ||
buf = "Hello"; | ||
char buffer[256]; | ||
|
||
|
||
// read one line at a time and send it to calc function for processing | ||
while(1) { | ||
char *s; | ||
char op; | ||
float x, y; | ||
fscanf(stdin, "%c %f %f", &op, &x, &y); | ||
switch (op) { | ||
case '+' : printf("%.2f\n", x + y); break; | ||
case '-' : printf("%.2f\n", x - y); break; | ||
case 'x' : printf("%.2f\n", x * y); break; | ||
case '/' : printf("%.2f\n", x / y); break; | ||
} | ||
} | ||
|
||
/* | ||
while ((s = fgets(buffer, 255, stdin)) != NULL) { | ||
float ans = calc(buffer); | ||
printf("%.2f\n", ans); | ||
} | ||
*/ | ||
return 0; | ||
} |