2. Draw Charts In this lab, you will make a C program to read a data file and dr
ID: 3872454 • Letter: 2
Question
2. Draw Charts In this lab, you will make a C program to read a data file and draw an xy chart for each data file based on the following guidelines: The filename is given as an optional argument of a command. If no argument is given, it prints a help message to guide a correct usage. Two data files are given ( dat). Each line of the data file contains two floating-point values as x and y. Draw x and y axis and ticks. Use arrows to positive directions. Draw the chart at the center of the paper. [Challenge] Find out appropriate x and y crosspoint. [Challenge] Draw labels. . ·Explanation / Answer
#include <stdlib.h>
#include <stdio.h>
#define NUM_POINTS 50
#define NUM_COMMANDS 50
int main()
{
float xvals[NUM_POINTS];
float yvals[NUM_POINTS];
char file[256];
scanf("%s",&file);
if(!file)
{
printf("Enter a filename for the program to work.");
}
fptr = fopen(file, "r");
FILE * temp = fopen(file, "w");
char ch = fgetc(fptr);
int i=0;
while(ch != EOF)
{
ch = fgetc(fptr);
xvals[i] = ch;
ch = fgetc(fptr);
yvals[i] = ch;
i++;
}
FILE * gnuplotPipe = popen ("gnuplot -persistent", "w");
fprintf(gnuplotPipe, "plot '-' ");
int i;
for (int i = 0; i < NUM_POINTS; i++)
{
fprintf(gnuplotPipe, "%f %f ", xvals[i], yvals[i]);
}
fprintf(gnuplotPipe, "e");
for (i=0; i < NUM_COMMANDS; i++)
{
fprintf(gnuplotPipe, "%s ", commandsForGnuplot[i]); //Send commands to gnuplot one by one.
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.