I'm using a c++ program (not MFC) to read input in via stdin then write back out using stdout.
type filename.txt | myprogram
stdout works fine, but stdin is giving me strange behavior.
1) I keep getting this error message
"The process tried to write to a non-existent pipe."
I have no idea what this means or what needs to be done to resolve it.
2) The first time I run my program, it reads in about half of my file in but then stops, after that it doesn't read anything in... if I recompile the program, it reads half a file again, and the cycle continues... now that's strange
Has anyone seen this before? Any ideas on what steps to resolve this?
Here's how I'm receiving input:
// file pointer to read file
FILE * pFile;
// receive input via stdin
pFile = stdin;
// obtain file size.
fseek (pFile , 0 , SEEK_END);
lSize = ftell (pFile);
// seek back to beginning of file
rewind (pFile);
// allocate memory to contain the whole file.
buffer = (char*) malloc (lSize);
// read the file buffer in
fread( buffer,1,lSize,pFile);
The data should all be in buffer, but it's not, only half of it on the first try, then it crashes!
type filename.txt | myprogram
stdout works fine, but stdin is giving me strange behavior.
1) I keep getting this error message
"The process tried to write to a non-existent pipe."
I have no idea what this means or what needs to be done to resolve it.
2) The first time I run my program, it reads in about half of my file in but then stops, after that it doesn't read anything in... if I recompile the program, it reads half a file again, and the cycle continues... now that's strange
Has anyone seen this before? Any ideas on what steps to resolve this?
Here's how I'm receiving input:
// file pointer to read file
FILE * pFile;
// receive input via stdin
pFile = stdin;
// obtain file size.
fseek (pFile , 0 , SEEK_END);
lSize = ftell (pFile);
// seek back to beginning of file
rewind (pFile);
// allocate memory to contain the whole file.
buffer = (char*) malloc (lSize);
// read the file buffer in
fread( buffer,1,lSize,pFile);
The data should all be in buffer, but it's not, only half of it on the first try, then it crashes!