Question
what is the mistake here? #include #include void get_corners(float x[], float y[]); int i; int ret; do { scanf(%lf,&x[i]; ret = scanf(%lf, &y[i]; } while(ret
what is the mistake here?
#include
void get_corners(float x[], float y[]); int i; int ret; do { scanf("%lf",&x[i]; ret = scanf("%lf", &y[i]; } while(ret >0); } int main(void) //define the main function { //declare the required variables char file[20]; float x[7],y[7];
//prompt the user to enter a file name printf("Enter a file name: "); scanf("%s",file);
//call the function get_corners by x_y_polygon.txt get_corners(file,x,y); }
//define the function get_corners void get_corners(char file[], float x[], float y[]) { FILE *fp; char file1[20]; int k =0,j=0,c=0; float i,area; fp = fopen(file,"r");
//check the file pointer if(fp==NULL) { //if fp is not null, enter into the else part } else { //use fscan to read the data from the file while(fscanf(fp,"%f",&i)==1) { c = c+1; //check the value of c if(c%2!=0) { //if c is not even, assign the value of i to array x and increment the counter k x[k]=i; k++; } //else part will execute when c is even else { //assign the value of i to array y and increment the j counter y[j] = i; j++; } }
//call the polygon_area function by x_y_polygon area= polygon_area(x,y,k);
//print the area of the polygon printf("Area of polygon = %.2f",area);
//prompt the user to enter the file name to write the data into file1 printf("Enter a file name to write the data: "); scanf("%s",file1); //call the output_corners function by x_y_polygon in order to write the data into file output_corners(file1,x,y,k);
//close the file fclose(fp); } }
//define the function polygon_area float polygon_area(float x[],float y[],int k) { //declaration and initilization float sum = 0.0,a,a1; int i;
//start the for loop for(i=0;i
//compute the absloute value of the variable sum a1 = fabs(sum);
//divide a1 by 2 to caculate the area of the polygon a = a1/2;
return a; }
//define the function output_corners void output_corners(char file1[],float x[],float y[],int k) { //declare a file pointer FILE *fp1; int i;
//open the file in write mode fp1 = fopen(file1,"w"); scanf("%lf", &i); //print characters in the file using fprint fprintf(fp1,"X\tY "); fscanf x[7](4-4-7-7-9-7-4) fscanf y[7](0-7.5-7.5-3-0-0-0-0) fprintf(fp1,"------------------");
//start the for loop for( i = 0;i //write the data to the file using fprintf fprintf(fp1,"%.2f\t%.2f ",x[i],y[i]); } //display the message printf("data is written into the file"); //close the file fclose(fp1); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started