Re: string compare
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Wed, 23 Jan 2008 03:00:38 -0500
yeti wrote:
I am using custom string structures in a project.
typedef struct {
short int length;
char data[256];
} my_long_string;
and
typedef struct {
short int length;
char data[32];
} my_short_string;
I want to create string processing functions like strcmp,
strcpy etc for these types.
I add indentation to your typedefs. Assuming your strings don't
need to handle the char '\0' you don't need to do anything. Just
stuff the data portion with C normal zero terminated strings. You
know that a long string can hold anything up to length 255, while a
short is limited to 31 chars. Then your compare etc. routines just
extract pointers to the data field from both and pass those to the
standard routines.
You might be better off making the structs completely common by:
typedef struct my_string {
size_t max_length, length;
char *data;
}
which is a fixed size, and serves you by not needing to eternally
recompute a length. However you do have to malloc space for *data
to point to, and record that maximum in max_length.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
--
Posted via a free Usenet account from http://www.teranews.com
.
- References:
- string compare
- From: yeti
- string compare
- Prev by Date: Re: Linux Kernel Source
- Next by Date: Re: string compare
- Previous by thread: Re: string compare
- Next by thread: Re: string compare
- Index(es):
Relevant Pages
|