I am making a program for a school where I have a multiprocessing program where each process reads a part of a file and they work together to count the number of words in a file. I have a problem: if there are more than two processes, all processes read the EOF from the file before they read their part of the file. Here is the relevant code:
#include <stdio.h>
Output when starting a file with three processes:
All files opened successfully Process 2 found unexpected EOF at 1323008. Process 1 found unexpected EOF at 823849. Process 0 found unexpected EOF at 331776.
Test file that causes the error: https://dl.dropboxusercontent.com/u/16835571/test34.txt
Compile with:
gcc main.c -o wordc-mp
and run as:
wordc-mp test34.txt 3
It is worth noting that only this particular file gives me problems, but the error offsets continue to change, so this is not the contents of the file.
source share