so the code is pretty simple. it just loops and if statements. first i have a main. i took the headers and prototypes out to make it smaller.
In main all iam doing is asking user to enter command and call one funtion.
// main.c

int main(int argc, char *argv[])
{
char command[10];

printf("Enter (a) to slove Linear equation(1 variable):\n");fflush(stdout);
printf("Enter (b) to slove Linear equation(2 variable):\n");fflush(stdout);
printf("Enter (slope) to find  Slope\n");fflush(stdout);
printf("Enter (exit) to  Exit:\n");fflush(stdout);
scanf("%s", command);
while(strcmp(command, "exit") != 0)
{
if(strcmp(command, "a") == 0)
{
linear_1(&buff1, &buff2);
}
printf("Enter (a) to slove Linear equation(1 variable):\n");fflush(stdout);
printf("Enter (b) to slove Linear equation(2 variable):\n");fflush(stdout);
printf("Enter (slope) to find  Slope\n");fflush(stdout);
printf("Enter (exit) to  Exit:\n");fflush(stdout);
scanf("%s", command);
}//end of while loop
return 0;
}

In this linear_1 function the while loop doesnt work.. for some reason it doesnt go inside while loop.
any one know how can i fix this.

while((ch = getchar()) != '\n')
{
two_side(ch, left_side, right_side, buff1);
}

already so here is linear_1 funtion below.

void linear_1(struct two_side *buff1, struct slove_eq *buff2)
{
char ch;

char left_side[SIZE];
char left_num[SIZE];
char left_var[SIZE];
char left_var_num[SIZE];
int l_total_num = 0;
int l_total_var = 0;

char right_side[SIZE];
char right_num[SIZE];
char right_var[SIZE];
char right_var_num[SIZE];
int r_total_num = 0;
int r_total_var = 0;

int ans_num = 0;
int ans_var = 0;

buff1->l = 0;
buff1->r = 0;
buff1->flag1 = 0;

set_null(left_side);
set_null(left_num);
set_null(left_var);
set_null(left_var_num);

set_null(right_side);
set_null(right_num);
set_null(right_var);
set_null(right_var_num);

printf("Enter a Linear equation(1 variable): ");fflush(stdout);
while((ch = getchar()) != '\n')
{
two_side(ch, left_side, right_side, buff1);
}

/**** Left_side: Sparate numbers from variables ****/
separate(left_side, left_num, left_var);

/**** Left_side: calculator numbers ***/
l_total_num = cal_number(left_num);

/********Left_side: variables to number ***/
variables_to_num(left_var, left_var_num);

/**** Left_side: calculator variables ***/
l_total_var = cal_number(left_var_num);

/**** Right_side: Sparate numbers from variables ****/
separate(right_side, right_num, right_var);

/**** Right_side: calculator numbers ***/
r_total_num = cal_number(right_num);

/******* Right_side: variables to number ***/
variables_to_num(right_var, right_var_num);

/**** Right_side: calculator variables ***/
r_total_var = cal_number(right_var_num);

/*** Slove equation ***/
slove_eq(l_total_var, l_total_num, r_total_var, r_total_num, buff2);

if(buff2->ans_var == 0)
{
printf("- Error -\n"); fflush(stdout);
}
else
{
printf("x = %d/%d\n",buff2->ans_num, buff2->ans_var); fflush(stdout);
}
}
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by WaltP

ahhh i found the problem. its when i enter a in main. ex, a\n
for some reason \n is going inside the linear_1 function. thats why its skiping the while loop.

but i still dont know how to fix this

See this. Check out the rest of the series, too.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.