1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main() {
FILE *fd, *file_out;
char buf[200], rec[200];
int sequences, session, i;
fd = fopen("summary.txt", "r");
if (fd == NULL) {
perror("Error");
exit(1);
}
file_out = fopen("ordinated.txt", "w");
if (file_out == NULL) {
printf("Error");
return -1;
}
while ( !feof(fd) ) {
fscanf(fd, "session %d (COPY MODE):\n\n", &session);
fscanf(fd, "number of sequences: %d\n\n", &sequences);
while (1) {
strcpy(rec, buf); // Save previous copy of buff so we can check if
fscanf(fd, "registration %d:\n\ncharacters recognized : %s\n\n", &i, buf);
if (!strcmp(rec, buf)) // Indicates end of session data
break;
fprintf(file_out, "%d %d %d %s\n", session, i, sequences, buf);
}
}
// Make sure to close the files
fclose(fd);
fclose(file_out);
}
|