0

If I use ./generate 10, I can successfully printf a random list, and if I use ./find 42, there successfully comes prompts to a ask me input numbers. However, if I use ./generate 10 | ./find 42, the result is just like:

haystack[0] = 
haystack[1] = 
haystack[2] = 
haystack[3] = 
haystack[4] = 
haystack[5] = 
haystack[6] = 
haystack[7] = 
haystack[8] = 
haystack[9] = 
haystack[10] =

I predict there should be int being saved in to haystack. Then I tried debug50 ./generate 10 | ./find 42,result:

WARNING: Could not set any breakpoints. Try deleting ./generate and re-compiling
your code. Be sure to compile with -ggdb3.

That beat me. I only typed codes in help.c and I didn't change the code in both generate.c and find.c, just like the guide said. Did I get something wrong?

1

What you are seeing is exactly what I'd expect, except that there should be a final line that says it either found or didn't find 42 in the haystack. Perhaps you didn't include that in your post?

The haystack values don't print as they are filled, but they will still be there.

As for debug50, you have to put breakpoints in your code (by clicking in the left margin next to the line number.)

To debug find you can generate a text file of numbers and then pipe that to find, like this

./generate 10 > nums.txt
./find 42 < nums.txt
3
  • It just like you said! I thought I can just put breakpoints only in find.c. After I put breakpoints in generate.c, it worked! Thank you so much! Jul 17 '17 at 6:01
  • Then I found the breakpoints in generate.c did work, but fail to stop in find.c or help.c, how could I set breakpoints in find.c with ./generate 10 | ./find 42? Jul 17 '17 at 12:44
  • See my edit on the answer
    – curiouskiwi
    Jul 17 '17 at 23:31
0

It sounds like this is what the output is supposed to look like. This was happening to me as well, and I wanted to be able to see which numbers were printing in the console to help me debug.

If you still want to see which numbers are being generated, just add a printf("%i", straw); on line 39 in your find.c file.

Fwiw, it turns out that my issue was in my searching algorithm, not in the piping mechanism from generate.c to find.c, like I thought.

You must log in to answer this question.

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