#include "BX40.h"
int citfig(FIG *p)
/*-reads the elements of a geometrical object defined by p->tip;
-returns:
0-for EOF;
1-otherwise*/
{
char t[255];
switch(p->tip){
case CERC: /*reads the radius of a circle*/
for( ; ; ){
printf("raza=");
if(gets(t) == 0)return 0;
if(sscanf(t,"%lf",&p->fig.raza)==1 &&
p->fig.raza>0)return 1;
printf("nu s-a tastat un numar pozitiv\n");
}
case PATRAT:/*reads the side of a square*/
for( ; ; ){
printf("latura patratului=");
if(gets(t) == 0)return 0;
if(sscanf(t,"%lf",&p->fig.lp)==1 &&
p->fig.lp>0)return 1;
printf("nu s-au tastat un numar pozitive\n");
}
case DREPTUNGHI:/*reads the length and the width of a rectangle */
for( ; ; ){
printf("lungimea si latimea pe aceeasi linie:");
if(gets(t) == 0)return 0;
if(sscanf(t,"%lf %lf",&p->fig.ld[0],&p->fig.ld[1])==2 &&
p->fig.ld[0]>0 && p->fig.ld[1]>0)return 1;
printf("nu s-a tastat 2 numere pozitiv\n");
}
case TRIUNGHI:/*reads the sides of a triangle*/
for( ; ; ){
printf("laturile triunghiului pe aceeasi linie ");
if(gets(t) == 0)return 0;
if(sscanf(t,"%lf %lf %lf",&p->fig.lt[0],&p->fig.lt[1,&p->fig.lt[2]])==3 &&
p->fig.lt[0]>0 && p->fig.lt[1]>0 && p->fig.lt[2]>0)return 1;
printf("nu s-au tastat 3 numere pozitive\n");
}
default:
return 0;
}
}
Could you please edit your original question and add the code to a CODE block? makes it much easier to read.
Also, do you get a line with the error message (in which error is it happening)?
You're code is almost indecipherable because of the lack of code tags and the formatting of your code and the code is also incomplete.
I'll try and point out the few problems I can spot.
You have missed the closing brace ("}") for the 2nd and third for loop.
You should never use an emptyforloop! For loops are used when you need to iterate through code a predefined number of times. Use while loops instead as they are for iterations where you don't know the number of iterations required to complete the operation.
Your if statements are very long. You may want to consider wrapping them in an appropriately name temporary bool variable, for the sake of clarity.
You also may want to consider inserting a few comments so your code is a little clearer.
Try posting the your full code so we can get a good look at the code.
While I try to avoid loops with constand conditions (while(true) and for( ; ; )), when I do use them I use for( ; ; ) as it avoids the "conditonal expression is constant" warning.
I don't think warnngs should ever be disabled globally, so the only other possibility is to disable the warning locally every time you use a while(true).
As I said, this shouldn't be that often. But code is cleaner with for( ; ; ) than the warning code.
I have edited my original post.hopefully is clearer now.
I corrected the missing braces but the original error is still on.
The if statements are used to read the size of the geometrical figure.
While loops are likethis?: while()
Sorry if i am short in words,but my keyboard damaged and i am using on-screen keyboard:)