How can I supplement this code printf("\nhaystack[%i] = ", size);that I can see the actual pseudorandom numbers that each i-th[] contain inside itself after haystack[1000] = using this command ./generate 1000 50 | ./find 127. Beacuse I only see an index in array i-th[] haystack[1000] =

Thank you!

for (size = 0; size < MAX; size++)
            // wait for hay until EOF
            printf("\nhaystack[%i] = ", size);
            int straw = get_int();  // It can get for example 1,000 or MAX = 65536 pseudorandom numbers from ./generate 1000 via pipe | ./generate 1000 50 | ./find 127 and then find needle
            if (straw == INT_MAX)

            // add hay to stack
            haystack[size] = straw;

1 Answer 1


If you want to see the automatically generated numbers when you pipe them in, you just need to add one line after the get_int() statement:

printf("%i", straw);

Bear in mind that if you now run find as a standalone program with no external input, the program will still reprint the number again after you enter it manually, displaying it twice.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .