Hi,
I have an unknown amount of input coming from a pipe into stdin from a child process to a parent. How would I store all of this into a variable so I am then able to process it several times?
Thanks
Hi,
I have an unknown amount of input coming from a pipe into stdin from a child process to a parent. How would I store all of this into a variable so I am then able to process it several times?
Thanks
Read all of it as you would any normal file and store it in some blob char array.
1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
3. Get rid of conio.h and other antiquated DOS crap headers.
4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.
Thinking about it you would require:
Some way to allocate a block of memory at will, of any size you like.
Some way to enlarge that block of memory at will, to any size you like.
Some way to read from the file.
Which sounds to me suspiciously like the bog-standard, well-documented, always-available, built-in C functions:
malloc
realloc
fopen/fread/fclose
- Compiler warnings are like "Bridge Out Ahead" warnings. DON'T just ignore them.
- A compiler error is something SO stupid that the compiler genuinely can't carry on with its job. A compiler warning is the compiler saying "Well, that's bloody stupid but if you WANT to ignore me..." and carrying on.
- The best debugging tool in the world is a bunch of printf()'s for everything important around the bits you think might be wrong.
It's really the "unknown" amount of input that sounds like somewhere along the way, a bad design decision was made.
1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
3. Get rid of conio.h and other antiquated DOS crap headers.
4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.