I have measured data divided into 100 steps. I want to read this data in C and save the temperature as a latex file. It should be output with a nice temperature curve. On the Y axis the temperature should appear and on the X axis the 100 steps. But this does not work for me. Can someone fix me the code? The data file looks like this:
x y temperature
0.292886,-0.015196,21.379749
.
.
.
X and y are not important. Only temperature is important
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
FILE *input_file, *tex_file;
input_file = fopen("result.csv", "r");
if (!input_file) {
printf("fail to open result.csv\n");
exit(1);
}
tex_file = fopen("path.tex", "w");
if (!tex_file) {
printf("fail to open path.tex\n");
exit(1);
}
// write tex head
const char *tex_head =
"\\documentclass{report} \\usepackage{tikz} \\begin{document} "
"\\begin{tikzpicture}[x=0.1cm,y=0.1cm] \\draw\n";
fputs(tex_head, tex_file);
char line[1024];
double x, y, z;
while (fgets(line, sizeof(line), input_file)) {
char *save = line;
char *_z = strtok_r(NULL, ",", &save);
z = atof(_z);
fprintf(tex_file, "(%f,%f,%f)--",z);
}
fprintf(tex_file, "(%f,%f,%f);\n", z);
// write tex tail
const char *tex_tail = "\\end{tikzpicture} \\end{document}";
fputs(tex_tail, tex_file);
fclose(input_file);
fclose(tex_file);
}