Storing Sentences in Linked List

This is a discussion on Storing Sentences in Linked List within the C Programming forums, part of the General Programming Boards category; I try to store a sentences in a struct of linked list (using malloc). I try fgets, scanf and gets ...

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    102

    Storing Sentences in Linked List

    I try to store a sentences in a struct of linked list (using malloc). I try fgets, scanf and gets but it never work. srry for not posting the code because it's an assignment.

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,801
    Your not going to get much in the way of help without code.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Apr 2011
    Location
    dust
    Posts
    66
    what was the error you got?
    Describe your problem clearly.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    First you write a small program to test your ability to extract sentences from user input.

    Say
    Code:
    char buff[BUFSIZ];
    char theSentence[BUFSIZ];
    while ( fgets( buff, sizeof(buff), stdin ) != NULL ) {
      // do stuff
      if ( sentenceComplete ) {
        printf("Found Sentence=%s\n", theSentence );
      }
    }
    When "Found Sentence=%s\n" is printing everything correctly for all sorts of input, then you put that to one side and work on the other problem.


    Say
    Code:
    list *myList = NULL;
    myList = addToList( myList, "The quick brown fox." );
    myList = addToList( myList, "Jumps over the lazy dog." );
    myList = addToList( myList, "This is your homework." );
    printList(myList);
    Again, when this is working as it should for a handful of fixed sentences.


    Then you can merge the two thing together by replacing
    printf("Found Sentence=%s\n", theSentence );
    with
    myList = addToList( myList, theSentence );
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Storing sentences in a 2-d array from a file
    By edmund085 in forum C Programming
    Replies: 4
    Last Post: 08-24-2011, 07:47 PM
  2. [help] - storing data from txt in linked list
    By Springy in forum C Programming
    Replies: 3
    Last Post: 10-17-2009, 09:14 AM
  3. Storing strings in a linked list
    By dws90 in forum C Programming
    Replies: 1
    Last Post: 02-21-2009, 06:06 PM
  4. Fork(), pause(), and storing PID's in a linked list
    By vital101 in forum C Programming
    Replies: 10
    Last Post: 09-28-2007, 02:16 AM
  5. Replies: 1
    Last Post: 03-02-2003, 07:42 AM

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