'Can't read data from text file written by c program

I am trying to write the number of packets I get to a textfile:

printf("TCP : %d   UDP : %d   ICMP : %d   IGMP : %d   Others : %d   Total : %d\r", tcp , udp , icmp , igmp , others , total);
if (usePacketCount == 1){
    fprintf(stderr,"Saving packet count");
    fprintf(packetCountFile,"TCP : %d   UDP : %d   ICMP : %d   IGMP : %d   Others : %d   Total : %d\r", tcp , udp , icmp , igmp , others , total);
}

When I run the program, I clearly get to this point in the code: enter image description here

However when I try to read the textfile, there is nothing present:

enter image description here

I define my file here:

FILE *packetCountFile = 0;

if (usePacketCount == 1){
    printf("Using Packet Count File");
    packetCountFile = fopen("packetCount.txt","w");
}

I am not sure why this is failing. It may be due to the write being in a loop, and it simply can't keep up?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source