Setting position indicators in Streams
Hello all, I need to be able to seek through a stream. This is a non-file stream, created by a pipe between my program and a subprogram, more specifically, created by the "popen()" function. Seeking position markers in a file stream is pretty easy, but it does not seem to be as straightforward with this kind of stream.
So far, I have tried the rewind() and fseek() functions, but these do not work (the first character scanned after a call to rewind() should be the first character in the stream again, but instead results in a EOF (and I know the stream was not empty)).
Is there something else I need to be doing, or are these types of streams (ones created by popen()) un-seekable?
Thanks for any help.
Here is a sample of the code I am using:
streamp = popen(COMMAND, "r");
//pass stream onto function
num_lines = get_num_lines(streamp);
//prints "10" in the specific case I am using, so I know stream is not empty.
//RESET marker to beginning of stream (I had hoped)
//instead this indicated that the marker was still at the end of the stream
if( fgetc(streamp) == EOF)
int num_lines = 0;
char ch, prev = NEWLINE;
while((ch = fgetc(streamp)) != EOF)
if(ch == NEWLINE)
prev = ch;
if(prev != NEWLINE)