Xref: utzoo comp.lang.c:38393 comp.lang.c++:12924 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!spool.mu.edu!munnari.oz.au!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.c,comp.lang.c++ Subject: Re: Parse file and copy words into doubly linked list? Message-ID: <5299@goanna.cs.rmit.oz.au> Date: 18 Apr 91 08:12:51 GMT Article-I.D.: goanna.5299 References: <13222.2809ff6e@ecs.umass.edu> Followup-To: comp.lang.c Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 28 In article <13222.2809ff6e@ecs.umass.edu>, mathews@ecs.umass.edu writes: > Could anyone suggest how to parse a text file and place each word in > a doubly linked list: > typdef struct list > { > char word[20]; > struct list *next; > struct list *prev; > }LIST, *LISTPTR; I have one comment on this. Why in the name of sanity is it char word[20]? Supposing for argument's sake that the words are to be English words (so that they will be relatively short), echo internationalisation | wc tells me that "internationalisation" has 21 letters. A quick scan through /usr/dict/words revealed 5 more words that would overflow such a tiny array. One of the most important things you should do in your programming assignment is check for such overflows and make sure that you do something sensible with them. while (fscanf(file, "%19s", WordBuffer) == 1) { /* WordBuffer holds the next "word" from the file */ } If that doesn't suit your notion of a word, %[ may be of use. -- Bad things happen periodically, and they're going to happen to somebody. Why not you? -- John Allen Paulos.