i have a project that i'm working on and i faces this problem
that gets in line 123 isn't work
note:
the project should be totally in c
that gets in line 123 isn't work
note:
the project should be totally in c
Code:
#include <stdlib.h>
#include <stdio.h>
#define size 1000000
#include <string.h>
void add_fractions (int a, int b, int c, int *d, int *ansn, int *ansd);
void subtract_fractions (int a, int b, int c, int *d, int *ansn, int *ansd);
void multiply_fractions (int a, int b, int c, int *d, int *ansn, int *ansd);
void divide_fractions (int a, int *b, int c, int *d, int *ansn, int *ansd) ;
void simplify(int *ansn,int *ansd);
int wordcon(FILE *in);
int main ()
{
int cho,cho1,x,z,a_num, b_denom, c_num, d_denom,ans1,ans2,numwd;
FILE *in;
char name[size];
while (x!=0)
{
printf("please enter :\n1- Fraction addition\n2- Fraction subtraction\n3- Fraction multiplication\n4- Fraction division\n5- File processing\n6- Exit\n");
scanf("%d",&cho);
x=1;
z=1;
switch (cho){
case 1:{
printf ("Please enter the first numerator> \n");
scanf ("%d", &a_num);
printf ("Please enter the first denominator> \n ");
scanf ("%d", &b_denom);
printf ("Please enter the second numerator> \n ");
scanf ("%d", &c_num);
printf ("Please enter the second denominator> \n ");
scanf ("%d", &d_denom);
add_fractions (a_num, b_denom, c_num, &d_denom,&ans1,&ans2);
if (d_denom==0)
printf("answer undefined\n");
else
{
simplify(&ans1,&ans2);
printf("the answer is = %d/%d\n",ans1,ans2);
}
}
break;
case 2 :{
printf ("Please enter the first numerator> \n");
scanf ("%d", &a_num);
printf ("Please enter the first denominator> \n ");
scanf ("%d", &b_denom);
printf ("Please enter the second numerator> \n ");
scanf ("%d", &c_num);
printf ("Please enter the second denominator> \n ");
scanf ("%d", &d_denom);
subtract_fractions (a_num, b_denom, c_num, &d_denom,&ans1,&ans2);
if (d_denom==0)
printf("answer undefined\n");
else
{
simplify(&ans1,&ans2);
printf("the answer is = %d/%d\n",ans1,ans2);
}
}
break;
case 3 :{
printf ("Please enter the first numerator> \n");
scanf ("%d", &a_num);
printf ("Please enter the first denominator> \n ");
scanf ("%d", &b_denom);
printf ("Please enter the second numerator> \n ");
scanf ("%d", &c_num);
printf ("Please enter the second denominator> \n ");
scanf ("%d", &d_denom);
multiply_fractions (a_num, b_denom, c_num, &d_denom,&ans1,&ans2);
if (d_denom==0)
printf("answer undefined\n");
else
{
simplify(&ans1,&ans2);
printf("the answer is = %d/%d\n",ans1,ans2);
}
}
break;
case 4: {
printf ("Please enter the first numerator> \n");
scanf ("%d", &a_num);
printf ("Please enter the first denominator> \n ");
scanf ("%d", &b_denom);
printf ("Please enter the second numerator> \n ");
scanf ("%d", &c_num);
printf ("Please enter the second denominator> \n ");
scanf ("%d", &d_denom);
divide_fractions (a_num, &b_denom, c_num, &d_denom,&ans1,&ans2);
if (d_denom==0||b_denom==0)
printf("answer undefined\n");
else
{
simplify(&ans1,&ans2);
printf("the answer is = %d/%d\n",ans1,ans2);
}
}
break;
case 5:{
while(z!=0){
printf("enter:\n1- count words in the file \n2- find and display characters with their frequencies \n3- search for a word in the file\n4- go to main menu\n5- Exit\n");
scanf("%d",&cho1);
switch (cho1){
case 1:[U]{
printf("Enter the name of file to be checked>\n");
char name[size];
gets(name);
in=fopen(name,"r");
if (in==NULL)
{
printf("ERROR - can't open file %s\n",name);
system("pause");
exit(0);
}
numwd=wordcon(in);
printf("%d\n",numwd);
}
break;[/U]
case 2 :printf("sunday\n");
break;
case 3 :printf("monday\n");
break;
case 4: z=0;
break;
case 5:{x=0;
z=0;}
break;
default: printf("wrong input\n");
}}}
break;
case 6 :x=0;
break;
default: printf("wrong input\n");
}}
system("pause");
return 0;
}
void simplify(int *ansn,int *ansd)
{
int x,y,a,z,gcd,rem;
x=*ansd;
y=*ansn;
if (y==0)
gcd = x;
else
{
do
{
rem = x%y;
x = y;
y = rem;
}
while (y!=0);
gcd = x;
}
*ansd=*ansd/gcd;
*ansn=*ansn/gcd;
}
void add_fractions (int a, int b, int c, int *d, int *ansn, int *ansd)
{
a = a*(*d);
c = c*b;
b = b*(*d);
*d = b;
*ansn = a + c;
*ansd = *d;
}
void subtract_fractions (int a, int b, int c, int *d, int *ansn, int *ansd)
{
a = a*(*d);
c = c*b;
b = b*(*d);
*d = b;
*ansn = a - c;
*ansd = *d;
}
void multiply_fractions (int a, int b, int c, int *d, int *ansn, int *ansd)
{
a = a*c;
c = a;
b = b**d;
*d = b;
*ansn = a;
*ansd = b;
}
void divide_fractions (int a, int *b, int c, int *d, int *ansn, int *ansd)
{
a = a*(*d);
*d = a;
*b = *b*c;
c = *b;
*ansn = a;
*ansd = *b;
}
int wordcon(FILE *in)
{
char str[size];
fgets(str, size, in);
char delims[] = " ";
char *token;
int numwd=0;
puts(str);
token = strtok( str, delims );
while ( token != NULL ) {
numwd++;
token = strtok( NULL, delims );
}
return numwd;
}
Comment