I have updated my file and it seemed to be working fine, however there is a minor glitch:
Code:
int main() {
double a, b, c, x1, x2;
int qret, count;
char line[30];
while(1) {
count=0;
printf("Enter variables for quadratic equation (Enter 'q' or 'quit' to exit): ");
fgets(line, 30, stdin);
if((strncmp(line, "quit", 4) > 0) || (strncmp(line, "q", 4) > 0))
return 0;
else
count = sscanf(line, "%lf %lf %lf", &a, &b, &c);
if(count != 3)
printf("Invalid Input: Format Is <double> <double> <double>\n\n");
else if(count == 3) {
qret = qsolver(a, b, c, &x1, &x2);
printf("Error Value: %d\n", qret);
printf("X1 = %lf X2 = %lf\n\n", x1, x2);
}
}
return 0;
}
for some reason the count returned by sscanf is 30 some of the time and im unsure as to why this is. I see that my array size is 30, but shouldn't sscanf() return the number of correctly read items?