pumpit
This commit is contained in:
parent
d9f282243a
commit
c513d24ba7
BIN
du4/program
BIN
du4/program
Binary file not shown.
@ -9,15 +9,11 @@
|
||||
#define SCAN_SECOND_NUMBER 2
|
||||
#define SCAN_SECOND_OPERATOR 3
|
||||
#define SCAN_RESULT 4
|
||||
// #define SCAN_END 5
|
||||
|
||||
char* scanValue(char *s, float *output);
|
||||
char* scanOperator(char *s, char *output);
|
||||
|
||||
// bool isDigit(char c);
|
||||
bool isOperator(char c);
|
||||
// bool isFloatingPoint(char c);
|
||||
// bool isWhitespace(char c);
|
||||
bool isNewline(char c);
|
||||
bool evaluate(float a, float b, float c, char op);
|
||||
|
||||
@ -25,17 +21,16 @@ void error();
|
||||
|
||||
int main(){
|
||||
char buffer[2048];
|
||||
// char str[512];
|
||||
char *retVal;
|
||||
|
||||
while ((retVal = fgets(buffer, sizeof(buffer), stdin)) != 0) {
|
||||
float a;
|
||||
float b;
|
||||
float c;
|
||||
char operator;
|
||||
|
||||
char *retVal = fgets (buffer, sizeof(buffer), stdin);
|
||||
|
||||
if (retVal == 0 || isNewline(buffer[0]) == true) {
|
||||
puts("KONIEC");
|
||||
// puts("KONIEC");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -52,16 +47,6 @@ int main(){
|
||||
char *currentChar = buffer;
|
||||
char *endChar = buffer + l - 1;
|
||||
|
||||
// for (char *i = 0; i < l; i++) {
|
||||
// // int forward = 0;
|
||||
|
||||
// char currentChar = buffer[i];
|
||||
|
||||
// if (i == l - 1 && isNewline(currentChar) == false) {
|
||||
|
||||
// }
|
||||
// }
|
||||
|
||||
while (currentChar < endChar) {
|
||||
if (scanStatus == SCAN_FIRST_NUMBER) {
|
||||
retVal = scanValue(currentChar, &a);
|
||||
@ -104,6 +89,7 @@ int main(){
|
||||
currentChar = retVal;
|
||||
scanStatus++;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -118,51 +104,6 @@ char* scanValue(char *s, float *output) {
|
||||
}
|
||||
|
||||
return retVal;
|
||||
|
||||
// int outPosition = 0;
|
||||
// int l = strlen(s);
|
||||
// bool hasPoint = false;
|
||||
|
||||
// for (int i = 0; i < l - 1; i++) {
|
||||
// char c = s[i];
|
||||
// char cNext = s[i+1];
|
||||
// bool isError = (outPosition == 0 && isDigit(c) == false)
|
||||
// || (outPosition > 0 && (
|
||||
// (hasPoint == true && isFloatingPoint(c))
|
||||
// || (hasPoint == false && isFloatingPoint(c) == true && isDigit(cNext) == false)
|
||||
// || (isDigit(c) == true && (
|
||||
// (hasPoint == true && isOperator(cNext) == false && isWhitespace(cNext) == false && isNewline(cNext) == false)
|
||||
// || (hasPoint == false && isOperator(cNext) == false && isWhitespace(cNext) == false && isNewline(cNext) == false && isFloatingPoint(cNext) == false))
|
||||
// )
|
||||
// || (hasPoint == true && isDigit(c) == false)
|
||||
// || (hasPoint == false && isFloatingPoint(c) == false && isDigit(c) == false)
|
||||
// ));
|
||||
|
||||
// if (isError == true) {
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
// if (isFloatingPoint(c)) {
|
||||
// hasPoint = true;
|
||||
// outPosition++;
|
||||
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// bool endsHere = isOperator(cNext) == true || isWhitespace(cNext) == true || isNewline(cNext) == true;
|
||||
|
||||
// if (endsHere == true) {
|
||||
// break;
|
||||
// }
|
||||
|
||||
// outPosition++;
|
||||
// }
|
||||
|
||||
// if (outPosition > 0) {
|
||||
// *output = strtof(s, s + outPosition - 1);
|
||||
// }
|
||||
|
||||
// return outPosition;
|
||||
}
|
||||
|
||||
char* scanOperator(char *s, char *output) {
|
||||
@ -183,22 +124,10 @@ char* scanOperator(char *s, char *output) {
|
||||
return start + 1;
|
||||
}
|
||||
|
||||
// bool isDigit(char c) {
|
||||
// return c >= '0' && c <= '9';
|
||||
// }
|
||||
|
||||
bool isOperator(char c) {
|
||||
return c == '+' || c == '-' || c == '*' || c == '/' || c == '=';
|
||||
}
|
||||
|
||||
// bool isFloatingPoint(char c) {
|
||||
// return c == '.' || c == ',';
|
||||
// }
|
||||
|
||||
// bool isWhitespace(char c) {
|
||||
// return c == ' ' || c == '\t';
|
||||
// }
|
||||
|
||||
bool isNewline(char c) {
|
||||
return c == '\n';
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user