If tested with input 12+12 it only prints the first integer (input1)
I want it to space it out and do the simple math like:
Input: 12+12
Output: 12 + 12 = 24
I know the math isnt there yet, im trying to get the getchar/putchar to work first. Also the class can only use getchar/putchar, so no string functions like isdigit or anything.
Thanks again guys!
Code:
#include <stdio.h>
int main(void)
{
int input1;
int oper;
int input2;
int numflag=0;
int signflag=0;
int end = 0;
/**Number 1**/
while ((input1 = getchar() ) && end!=1)
{
if ((input1 >= '0') && (input1 <= '9'))
{
putchar(input1);
numflag=1;
}
else if (numflag==1)
{
putchar(' ');
numflag=0;
end=1;
}
}
/**Operator**/
while ((oper = getchar() ) && end!=1)
{
if ((input1 == '+') || (input1 == '-') || (input1 == '*')
|| (input1 == '/') || (input1 == '%'))
{
putchar(oper);
numflag=1;
}
else if (numflag==1)
{
putchar(' ');
numflag=0;
end=1;
}
}
/**Number 2**/
while ((input2 = getchar() ) && end!=1)
{
if ((input2 >= '0') && (input2 <= '9'))
{
putchar(input2);
numflag=1;
}
else if (numflag==1)
{
putchar(' ');
numflag=0;
end=1;
}
}
return 0;
}