So I'm really new to C and I'm fiddling around trying to get some small programs to work. At the moment I am working on a program that simply lets a user input a linear equation and prints it out. It should be able to differentiate between the coefficients and the Variables / Operators so that I can use it later.
My problem is that I don't know of a proper way to scan the input and the solution I have right now seems rather janky:
#include <stdio.h>
#include <math.h>
// a+b+c+d+[...]=n
double Numbers[9]; //Storing the coefficients
char Variable[9]; //Space for storing different variables
char Operator[9]; //Space for storing different operators
int main()
{
printf("Enter your linear equation:\n");
int n = 0; //Index value for the arrays
do
{
scanf("%lf", &Numbers[n]);
scanf(" %c", &Variable[n]);
scanf(" %c", &Operator[n]);
n++;
} while (Operator[n-1] != '='); //Stops as soon as a '=' has been recognized, which signals the end of the equation
scanf("%lf", &Numbers[n]); //scans for the last number after the '='
int NumVar = n; //Stores the total number of variables
while (n > 0)
{
printf("%f%c%c", Numbers[NumVar - n], Variable[NumVar - n], Operator[NumVar - n]); //Substracting 'NumVar' from 'n'
n--;
}
printf("%f", Numbers[NumVar]);
return 0;
}
PS: pls keep in mind that I am very new to pointers