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.
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.
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
what was the error you got?
Describe your problem clearly.
First you write a small program to test your ability to extract sentences from user input.
Say
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.Code:char buff[BUFSIZ]; char theSentence[BUFSIZ]; while ( fgets( buff, sizeof(buff), stdin ) != NULL ) { // do stuff if ( sentenceComplete ) { printf("Found Sentence=%s\n", theSentence ); } }
Say
Again, when this is working as it should for a handful of fixed sentences.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);
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.