I have a problem that I cannot understand with printf. This is the first time I have this problem, so I'm sure it is something naive, but no matter what, I can not solve it myself ... maybe it's just because I'm tired: fprintf (and I found this also true for printf) only the first argument prints correctly, from the second it will print only "0" for numbers and "(null)" for strings
Here is the relevant code:
#include <math.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> void printInputStream(MatePair* inputStream, char* leftFile, char* rightFile){ MatePair* iterator = inputStream; FILE* outLeft = fopen(leftFile, "w"); FILE* outRight = fopen(rightFile, "w"); while (iterator->leftRow != MATEPAIR_STOP){ fprintf(outLeft, "%d: \n", iterator->leftRow); fprintf(outLeft, "%s \n", iterator->leftDNA); fprintf(outLeft, "%d: %s \n", iterator->leftRow, iterator->leftDNA); iterator++; } fclose(outLeft); fclose(outRight); }
Here's the beginning of the output:
48: NAATAGACCTATATCCTGTACCCAAACAGAAGACAGAGGATTAACCAAACTCTT 48: (null) 44: NTAGCCATCTTAGACACATGAATATCTTGGGTCACAACTCATACCTCAACAAAA 44: (null) 40: NAAAATAAGGGGTATACTCGCTTCGGGGCCCCATTTGGCCTCCAAAAGGGGGCG 40: (null) 36: NTCTATCTTGCTCGAGAGAAAGGGTTGCCTTAGGGTTTTTTGGGGGGGGCTGTA 36: (null) 32: NCTATAGAAATTTCCCATACCAACTAGACATTTATCTTCCTGTTTTTTTCCGCC 32: (null)
As you can see, I print each member of the array twice: once for each argument and both arguments together. The data is in order, in fact with the first method all this is normal, with the second only the first argument is output. Any ideas? thanks in advance
Alex source share