Originally Posted by
Matticus
Do you know how to open a file for reading? If not, read up on it and practice writing code that opens a file. (Be sure to check that the file opens successfully.)
Do you know how to read from an opened file? If not, read up on it and practice writing code that reads from a text file. (Check by printing out what you've read from the file.)
Do you know how to parse data from a string? If not, figure out how to check the contents of a string so you can process it as needed.
I could do this part but the rest I dont know like rounding and partitioning etc...
Code:
#include <stdlib.h>
#include <stdio.h>
#define LINE_MAXLENGTH 80
int main()
{
float a, b;
char operations;
FILE* cmd = fopen("CommandsProj1.dat", "r");
if (cmd == NULL)
{
printf("Error Code (404)");
return EXIT_FAILURE;
}
int line[LINE_MAXLENGTH + 1];
while (fgets(line, LINE_MAXLENGTH + 1, cmd))
{
float result;
line[strcspn(line, "\n")] = '\0';
if (strcmp(line, "DA") == 0)
{
}
else if (strcmp(line, "Q") == 0)
{
}
else if (strcmp(line, "H") == 0)
{
printf("Help Bar +, -, *, /, H, Q\n");
continue;
}
else if (sscanf(line, "%c %f %f", &operations, &a, &b) == 3)
{
switch (operations)
{
case '+':
result = a + b;
break;
case '-':
result = a - b;
break;
case '*':
result = a * b;
break;
case '/':
result = a / b;
break;
default:
continue;
}
printf("%c Operator: %.1f %c %.1f = %.1f \n", operations, a, operations, b, result);
}
}
return EXIT_SUCCESS;
}