I have a file called test.xml. What I am trying to do is print everything before the into a new file called. Then print my own custom <start>n n n</start>
. Then print everything after the </start>
test.xml:
<more tests = 42 and more "34">
<start>10.213123 41.21231 23.15323</start>
<random stuff = "4">
<blah 234>
I tried using memcmp, doesn't seem to work.
// The main hub for generating new files with all the information in it.
void create_new_files(FILE *original, char *new_name, double x, double z,
double y, int val_pos, int incr_val, int max_val) {
double i = 0;
y = 10.1234;
z = 30.231;
FILE *generated_file = fopen(new_name, "r");
// suppose to print everything before the <start>
print_top_section(original);
fprintf(generated_file, "<start>%lf %lf %lf</start>\n\n", i, z, y);
// suppose to print everything after </start>
print_bottom_section(original);
fclose(generated_file);
}
// Prints the top section before it sees <start>
void print_top_section(FILE *original) {
char line[MAX_LINE_LENGTH];
while (memcmp(line, "<start>", sizeof("<start>")-1)) {
fputs(line, stdout);
}
}
// Prints the bottom section after it sees </start>
void print_bottom_section(FILE *original) {
char line[MAX_LINE_LENGTH];
while (memcmp(line, "</start>", sizeof("</start>")-1)) {
fputs(line, stdout);
}
}
Trying to make it so the output would be:
<this is a test = 1>
<more tests = 42 and more "34">
<start>0 10.1234 30.231</start> // This is my own custom line.
<random stuff = "4">
<blah 234>