Re: advice needed
- From: Micah Cowan <micah@xxxxxxxxxx>
- Date: Wed, 08 Mar 2006 05:07:26 GMT
Al Balmer <albalmer@xxxxxxx> writes:
On Tue, 07 Mar 2006 23:30:26 GMT, John Smith <JSmith@xxxxxxxx> wrote:
Al Balmer wrote:
On Tue, 07 Mar 2006 19:50:28 GMT, John Smith <JSmith@xxxxxxxx> wrote:
I've written a program in C that does statistical analysis of
text files. The program fscanf()s strings (words) into a
statically allocated 32-byte buffer. 32 bytes is enough to
accomodate the longest English word, but if the input file
contains a non-word string longer than 32 bytes the program will
seg fault. I could increase the buffer to some huge size but
that's wasteful and doesn't solve the problem anyway: there could
always be some huge string 1 byte bigger than my huge buffer.
AFAIK, it's not possible to "trap" a seg fault. If this was your
project, how would you deal with the problem?
Don't use fscanf(). It's the wrong tool for the job.
1. Why is it the wrong tool?
For the reason you stated above, for one.
Although, he could use the field width limiter:
fscanf(file, "%31s", str);
But that's hardly the handiest solution...
- Prev by Date: Re: advice needed
- Next by Date: Re: Help regarding Building a small C++ to C compiler (Translator)
- Previous by thread: Re: advice needed
- Next by thread: Re: advice needed