I don't know how to explain this in debug

  • Thread starter yungman
  • Start date
  • Tags
    Explain
In summary, the conversation discusses a program that adds names to a vector and sorts them in ascending order. The conversation also mentions a specific issue where a conditional statement does not work as expected. The conversation ends with a suggestion to check various components, such as the vector and strings, to see if they are properly initialized and allocated.
  • #36
jedishrfu said:
What was the value of midpoint?

When I look at failing statements like this in Java I look at these components:
- DirV - is it null or a bad-pointer?
- midPt - is the value within the range of 0<= midPt < length of the array ?
- DirV[midPt] - does the DirV[midPt] string look okay or is it not initialized or not what you expect?
- Dir - is it null or a bad-pointer?
- Dir.name - is the string what you expect?

I saw where you defined the DirV structure and used char name[namelen] but in your code I don't see any strcpy of Dir.name to that string? I also saw where you assign Dir to DirV but never allocate new space for Dir. This means that DirV will contain the pointer to Dir and since you didn't allocate new space every entry in DirV will point to the same Dir and will all get changed when you change the contents of Dir.

https://www.geeksforgeeks.org/strcpy-in-c-cpp/

Does that make sense?

Line 38 I see where you're doing a string compare which is really comparing pointers and not the strings.

http://www.cplusplus.com/reference/string/string/compare/
Definitely agree with jedishrfu - But I Would suggest you to read these articles ;

[Spam links deleted and spammer banned]
 
Last edited by a moderator:
Technology news on Phys.org
  • #37
Thanks for sharing your insight here but since the thread is quite old I’m sure the OP has resolved his difficulties or moved to a new profession.

Time now to close this thread.
 

Similar threads

  • Programming and Computer Science
3
Replies
75
Views
4K
  • Programming and Computer Science
Replies
30
Views
2K
  • Programming and Computer Science
Replies
32
Views
2K
  • Programming and Computer Science
2
Replies
66
Views
4K
  • Programming and Computer Science
Replies
5
Views
897
Replies
10
Views
973
  • Engineering and Comp Sci Homework Help
Replies
3
Views
2K
  • Programming and Computer Science
Replies
3
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
6K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
Back
Top