Computer Science Canada structs, pointers and linked list |
Author: | jin [ Sun Nov 26, 2006 12:35 am ] | ||||
Post subject: | structs, pointers and linked list | ||||
Hey i am using a struct and forming a linked list when i output it i get the element and then a weird symbol followed by w. Struct
Adding in list
Thanks |
Author: | md [ Sun Nov 26, 2006 1:31 am ] |
Post subject: | |
Except for the ugly C strings (std::string is your friend) I see nothing wrong with this code. Can you post all of your code? That would make debugging easier. |
Author: | jin [ Sun Nov 26, 2006 1:41 am ] | ||
Post subject: | |||
|
Author: | md [ Sun Nov 26, 2006 11:02 am ] | ||
Post subject: | |||
Oh boy... So g++ gives me the following warnings: g++ wrote: test.c: In function 'int main()': test.c:39: warning: unused variable 'key' test.c: In function 'void Remove_Punctuation(char*)': test.c:72: warning: comparison between signed and unsigned integer expressions test.c:76: warning: comparison between signed and unsigned integer expressions test.c:85: warning: comparison between signed and unsigned integer expressions test.c: In function 'void Change_Case(char*)': test.c:100: warning: comparison between signed and unsigned integer expressions While they are not serious, you may want to look into them. Second, since you are using C++ I HIGHLY recommend using std::string instead of C strings. The problem with your code seems to stem from Read(). When you read your words you do not terminate your C string properly (you wouldn't have to with std::string!). Aside from that and some rather bizzare logic I can't see anything immediately wrong. There are also a whole lot of code formatting things and code inconsistencies that should be fixed... ![]() Because I am in a good mood... here ya go ![]()
All using std::strings, etc. I also fixed most (if not all) of hte formatting problems, but I left some of the extraneous comments. |
Author: | jin [ Sun Nov 26, 2006 12:33 pm ] | ||
Post subject: | |||
Thanks but we are supposed to use c-strings and also have not learned the format style you use. Here is my finished program if you have any comments on how to make better please let me know. (especially about the deletelist function). This basically reads words from a file and stores them in a linked list and how many times they appear. It also lets you search for words in the list.
|