Re: Why segfault and no NULL match in for loop?
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Wed, 02 May 2007 20:14:34 -0400
somebody wrote:
.... snip to content of search.h ...
There are two files below named search.c and search.h. In the for
loop in search.c, the for loop never exits, even if
mystruct[i].field1 has no match. Instead of exiting the for loop
it keeps going until it segfaults. This seems to be related to the
strcmp with the NULL value. There are 2 comments below that
indicate the segfaults. I guess the question is, when there is no
match, how to I detect that and return without a segfault?
struct _mystruct mystruct[] =
{
"AAA", "EEE", "R", "DF", 25,
"BBB", "FFF", "R", "DF", 25,
"CCC", "GGG", "R", "DF", 99,
"DDD", "HHH", "R", "DF", 13,
};
NEVER define an actual object in a .h file. Doing so will cause it
to be multiply defined, and result in link or run time errors. Add
the word "extrn" to the definition, and delete the initialization.
Put the above structure in ONLY one of the files in which you
#include "search.h".
A .h file is NOT a place for headers, it is a place to define the
data you want to export from a .c file.
--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
<http://kadaitcha.cx/vista/dogsbreakfast/index.html>
cbfalconer at maineline dot net
--
Posted via a free Usenet account from http://www.teranews.com
.
- Follow-Ups:
- Re: Why segfault and no NULL match in for loop?
- From: jaysome
- Re: Why segfault and no NULL match in for loop?
- From: Keith Thompson
- Re: Why segfault and no NULL match in for loop?
- References:
- Why segfault and no NULL match in for loop?
- From: somebody
- Why segfault and no NULL match in for loop?
- Prev by Date: Re: debounce state diagram FSM
- Next by Date: Re: malloc call not returning
- Previous by thread: Re: Why segfault and no NULL match in for loop?
- Next by thread: Re: Why segfault and no NULL match in for loop?
- Index(es):
Relevant Pages
|