Thread: Storing Sentences in Linked List

  1. #1
    Registered User
    Join Date
    Aug 2011

    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
    Northern Virginia/Washington DC Metropolitan Area
    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
    what was the error you got?
    Describe your problem clearly.

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

    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.

    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." );
    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 );
    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.

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, 07: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, 08:42 AM