struct probelm

This is a discussion on struct probelm within the C++ Programming forums, part of the General Programming Boards category; i am a beginner, i am doing a program that user can input the filename, and i can run in ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    3

    struct probelm

    i am a beginner, i am doing a program that user can input the filename, and i can run in to count the word frequency using link list.
    i have 5 list operation, like create, add, search, print, and delete.

    BUT the main problem i faced is when doing the struct, i don't know how to define the structure? if i using char* in word, then i don't know how to get the string(word) into the link list when i using char* to define now....
    anybody can help me. really don't know how to do

    struct Node {
    int count;
    char* word;
    struct Node* next;
    struct Node* theList;
    };

  2. #2
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320
    First thing, put your code in code tags....
    Second, What do you mean by frequency?
    If you mean the count of number of words, what's the problem, you can use built in string function strlen(your_String) to find the length of the string.....

    I am not sure, what are you asking about....
    Be more specific so that i could think over...

    Regards...

  3. #3
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    671
    Code:
    struct Node {
        int count;
        char* word;
        struct Node* next;
        struct Node* theList;
    };
    I have no idea how it is going to work. Is this your assignment? If not, don't create your own linked list (unless you want to try to implement it for educational purposes). Use std::list as linked list and std::wstring instead of char*. Instead of creating whole structure you could just write:

    Code:
    std::list<std::wstring> Words;
    I never put signature, but I decided to make an exception.

  4. #4
    Registered User bobknows's Avatar
    Join Date
    Jan 2011
    Location
    SD
    Posts
    87
    if you want to count the words just see how many whitespace have letters after them like this
    Code:
    //put the file into a string 
    int wordcount = 0;
    for(int i = 0; i < strlen(string); i++)
         if(string[i] == ' ' && string[i+1] != ' ')
                wordcount++;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. casting struct to struct
    By klmdb in forum C Programming
    Replies: 6
    Last Post: 08-14-2010, 02:29 PM
  2. I'm donating my vector lib.
    By User Name: in forum C Programming
    Replies: 23
    Last Post: 06-24-2010, 06:10 PM
  3. help with structs and malloc!
    By coni in forum C Programming
    Replies: 20
    Last Post: 09-14-2009, 05:38 PM
  4. Replies: 1
    Last Post: 12-03-2008, 02:10 AM
  5. Replies: 10
    Last Post: 05-18-2006, 11:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21