473,385 Members | 1,912 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

String search and length portability questions

I have taken an intro evening C course at a local university, but my
C programming experience is otherwise nill. I've come up with a little
project that I want to cut my teeth on. After reading the FAQ, I have a
few questions

1) What proportion of modern OSs/compilers would a string in excess of
64K charcters break ?

2) Is memmem a standard function in C ? I want to find if and where a
smaller string exists within a larger string. Spelunking through
/usr/include/string.h (Redhat 7.3; gcc 2.96) I find...

#ifdef __USE_GNU
/* Find the first occurrence of NEEDLE in HAYSTACK.
NEEDLE is NEEDLELEN bytes long;
HAYSTACK is HAYSTACKLEN bytes long. */
extern void *memmem (__const void *__haystack, size_t __haystacklen,
__const void *__needle, size_t __needlelen)
__THROW __attribute_pure__;

The call looks simple. The parameters would be
- pointer to larger (containing) string
- containing string size (why size_t rather than int ?)
- pointer to substring
- substring size (why size_t rather than int ?)

If the function is void, how do I find out what it has returned ?

3) Is there a list somewhere on the web of standard functions and the
libraries they're found in ?

4) What does fubar_t signify, where fubar can be anything ? This
looks like some sort of standard naming convention.

--
Walter Dnes <wa******@waltdnes.org>
Email users are divided into two classes;
1) Those who have effective spam-blocking
2) Those who wish they did
Nov 13 '05 #1
4 2291
Walter Dnes wrote:
2) Is memmem a standard function in C?
No. Type

man memmem

at your Linux prompt.
I want to find if and where
a smaller string exists within a larger string.


Use strstr.

Nov 13 '05 #2

"Walter Dnes" <wa******@waltdnes.org> wrote in message

1) What proportion of modern OSs/compilers would a string in excess
of 64K charcters break ?

Not many. It was really only the old DOS compilers which imposed a limit of
64K.
However a C string is NUL terminated, which means that to do anything much
with it the computer has to scan through to the end. For a string as long as
64K this could be fairly slow, so it would be unusual to store a character
sequence that long as a single string.

Nov 13 '05 #3
On Wed, 23 Jul 2003 01:01:09 GMT, Artie Gold, <ar*******@austin.rr.com> wrote:
3) Is there a list somewhere on the web of standard functions and the
libraries they're found in ?


The libraries in which they are found sometimes varies.
http://www.dinkumware.com/refxc.html provides a reference.


A little bit more spelunking allowed me to create a list of all
occurences of "#include fubar.h" in /usr/share/man/3. Here it is for
everybody else's benefit...

#!/bin/bash
cd /usr/share/man/man3
ls -1 |\
grep ^[a-z] |\
xargs zcat |\
grep \#include |\
sed "s/^.* <//
s/>.*$//" |\
sort -u > ~/liblist.txt

I can "man" the libraries, and get a list of included functions.

--
Walter Dnes <wa******@waltdnes.org>
Email users are divided into two classes;
1) Those who have effective spam-blocking
2) Those who wish they did
Nov 13 '05 #4
In <bf**********@news8.svr.pol.co.uk> "Malcolm" <ma*****@55bank.freeserve.co.uk> writes:

"Walter Dnes" <wa******@waltdnes.org> wrote in message

1) What proportion of modern OSs/compilers would a string in excess
of 64K charcters break ?
Not many. It was really only the old DOS compilers which imposed a limit of
64K.


And not even the DOS implementations imposed such a limit if you
didn't mind the overhead of using the huge memory model. The programmer
had to choose between fast and compact code that couldn't manipulate
objects larger than 64K and somewhat slower code that could transparently
handle any object fitting into the memory available to the program.
However a C string is NUL terminated, which means that to do anything much
with it the computer has to scan through to the end.
There are plenty of things you can do without having to scan through to
the end: strchr, strstr, str[c]spn, str[n]cmp, strncpy. I would have
added sscanf, but apparently it is not that uncommon for sscanf
implementations to call strlen on their first parameter before starting
the actual scanning.
For a string as long as
64K this could be fairly slow, so it would be unusual to store a character
sequence that long as a single string.


It depends on the application domain. If it makes sense to have strings
that long, you just use them.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Angus Comber | last post by:
Hello My code below opens a Word document in binary mode and places the data into a buffer. I then want to search this buffer for a string. I tried using strstr but think it stops looking when...
14
by: Walter Dnes (delete the 'z' to get my real address | last post by:
I took a C course some time ago, but I'm only now beginning to use it, for a personal pet project. My current stumbling-block is finding an efficient way to find a match between the beginning of a...
7
by: Sky | last post by:
I have been looking for a more powerful version of GetType(string) that will find the Type no matter what, and will work even if only supplied "{TypeName}", not the full "{TypeName},{AssemblyName}"...
1
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ 3.5. - How do I convert a Number into a String with exactly 2 decimal places?...
6
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
10
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
1
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.