473,396 Members | 1,998 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,396 software developers and data experts.

string search?

Hello, Im working on a little LAN game in the style of old text-only
MUD's and would need to find a way to search for a string in a text
file (for example for usernames). I know it works in the way of looking
for the first letter, if matches the second and so on, but don't know
how to write it. Any suggestions?

Oct 31 '06 #1
33 2413
Bertram Trabant said:
Hello, Im working on a little LAN game in the style of old text-only
MUD's and would need to find a way to search for a string in a text
file (for example for usernames). I know it works in the way of looking
for the first letter, if matches the second and so on, but don't know
how to write it. Any suggestions?
Look up "Boyer-Moore" or "Knuth-Morris-Pratt".

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Oct 31 '06 #2
On Tue, 2006-10-31 at 04:09 -0800, Bertram Trabant wrote:
Hello, Im working on a little LAN game in the style of old text-only
MUD's and would need to find a way to search for a string in a text
file (for example for usernames). I know it works in the way of looking
for the first letter, if matches the second and so on, but don't know
how to write it. Any suggestions?
Well, you could attempt to read the third volume of Knuth's /The Art of
Computer Programming/. If you try it, I wish you all the luck in the
world.

Otherwise, you could try asking in comp.programming for pseudocode.
You'd probably get more help there.

--
Andrew Poelstra <http://www.wpsoftware.net>
For email, use 'apoelstra' at the above site.
"You're only smart on the outside." -anon.

Oct 31 '06 #3
On 31 Oct 2006 04:09:24 -0800, "Bertram Trabant"
<ni**********@gmail.comwrote:
>Hello, Im working on a little LAN game in the style of old text-only
MUD's
A hobbyist program, I daresay.
>and would need to find a way to search for a string in a text
file (for example for usernames). I know it works in the way of looking
for the first letter, if matches the second and so on, but don't know
how to write it. Any suggestions?
You have 2 possibilities depending on your requirements:
1. Search directly in the file using stdio functions like fopen,
fread, fgets, fgetc, fseek, ftell, fclose ...

2. Read the whole or parts (e.g. single lines) of the file into a
string and search the string. For that you need malloc and free for
(de-)allocation (or a fixed size buffer), the aforementioned stdio
functions and strstr to find the substring.

Good luck,
Roland Pibinger
Oct 31 '06 #4
Bertram Trabant wrote:
Hello, Im working on a little LAN game in the style of old text-only
MUD's and would need to find a way to search for a string in a text
file (for example for usernames). I know it works in the way of looking
for the first letter, if matches the second and so on, but don't know
how to write it. Any suggestions?
If you are going to be doing a fair amount of string manipulation in C
for this project then I suggest you do one of two things:

1. Implement a string handling library of your own
2. Use one of the many string libraries that are out there

The first is a fine way to get your chops down, but it may delay the
actual fun part of the development for you, namely writing the game.
Oct 31 '06 #5

Roland Pibinger wrote:
On 31 Oct 2006 04:09:24 -0800, "Bertram Trabant"
<ni**********@gmail.comwrote:
Hello, Im working on a little LAN game in the style of old text-only
MUD's

A hobbyist program, I daresay.
Oh yes, it's absolutely nothing professional, just a way to kill time
and make sarcastic comments about others.
2. Read the whole or parts (e.g. single lines) of the file into a
string and search the string. For that you need malloc and free for
(de-)allocation (or a fixed size buffer), the aforementioned stdio
functions and strstr to find the substring.
This looks good. Do commands like getc() use some sort of "cursor" in
the file? That would be a huge time-saver (Stupid code, clever file).

Also, thanks to everybody else who helped.

Nov 1 '06 #6
On 1 Nov 2006 00:37:32 -0800, "Bertram Trabant"
<ni**********@gmail.comwrote:
>
Do commands like getc() use some sort of "cursor" in
the file? That would be a huge time-saver (Stupid code, clever file).
You may have a look at an introductionary C book or an online tutorial
like:
http://www-ee.eng.hawaii.edu/Courses/EE150/Book/
http://computer.howstuffworks.com/c.htm/
Best wishes,
Roland Pibinger
Nov 1 '06 #7
Bertram Trabant wrote:
Do commands like getc() use some sort of "cursor" in
the file?
They use a "file position indicator",
if that's what you mean.

--
pete
Nov 1 '06 #8
Roland Pibinger wrote:
On 1 Nov 2006 00:37:32 -0800, "Bertram Trabant"
<ni**********@gmail.comwrote:
>Do commands like getc() use some sort of "cursor" in
the file? That would be a huge time-saver (Stupid code, clever file).
You may have a look at an introductionary C book or an online tutorial
like:
http://www-ee.eng.hawaii.edu/Courses/EE150/Book/
I would not recommend this one. In the first C program it used the very
old fashioned definition of main:
main()
{
}

It failed to #include <stdio.hbefore using printf.

It then went on to specify specific sizes for types (sizes that are
wrong on many modern systems) without mentioning that they depended on
the particular implementation.

In another program it went on to using scanf (again without a prototype
in scope) without checking the return value or ensuring that the
previous prompt will have been displayed. Then it only does while loops,
not for loops. I could go on.
http://computer.howstuffworks.com/c.htm/
I can't recommend this either. This started off looking better until it
suggested using gets in real programs and did not check the return value
of scanf and again did not ensure prompts were displayed.

Then the author goes on to assume that there is an implicit conversion
between a function pointer and an int. It was suggesting that C would accept
x = rand
when what was wanted was
x = rand()
Obviously, x is an int and rand is a function returning an int. As
everyone here knows the first line would *require* a diagnostic.

The comp.lang.c FAQ, K&R2 (see the bibliography of the comp.lang.c FAQ)
and many other books that have been recommended here would be far better.
--
Flash Gordon.
Nov 1 '06 #9
They use a "file position indicator",
if that's what you mean.
This looks good. Is there any way of directly controlling it?

Nov 1 '06 #10
pete napísal(a):
They use a "file position indicator",
if that's what you mean.
This looks promising, is there any way of directly controlling it?

Nov 1 '06 #11
Bertram Trabant said:
pete napísal(a):
>They use a "file position indicator",
if that's what you mean.

This looks promising, is there any way of directly controlling it?
Look up ftell, fseek, fgetpos, and fsetpos.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Nov 1 '06 #12
Flash Gordon said:
Roland Pibinger wrote:
>On 1 Nov 2006 00:37:32 -0800, "Bertram Trabant"
<ni**********@gmail.comwrote:
>>Do commands like getc() use some sort of "cursor" in
the file? That would be a huge time-saver (Stupid code, clever file).
You may have a look at an introductionary C book or an online tutorial
like:
http://www-ee.eng.hawaii.edu/Courses/EE150/Book/

I would not recommend this one. In the first C program it used the very
old fashioned definition of main:
main()
{
}
Hardly a killer. After all, K&R2 does this as well.
>
It failed to #include <stdio.hbefore using printf.
That's rather more serious. Taken with the other issues you mentioned, it's
enough to scupper any tutorial.

<snip>
>
>http://computer.howstuffworks.com/c.htm/

I can't recommend this either. This started off looking better until it
suggested using gets in real programs
Ouch!
The comp.lang.c FAQ, K&R2 (see the bibliography of the comp.lang.c FAQ)
and many other books that have been recommended here would be far better.
See also:

* http://www.eskimo.com/~scs/cclass/
* http://cprog.tomsweb.net/cintro.html

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Nov 1 '06 #13
Richard Heathfield wrote:
Flash Gordon said:
>Roland Pibinger wrote:
>>On 1 Nov 2006 00:37:32 -0800, "Bertram Trabant"
<ni**********@gmail.comwrote:
Do commands like getc() use some sort of "cursor" in
the file? That would be a huge time-saver (Stupid code, clever file).

You may have a look at an introductionary C book or an online tutorial
like:
http://www-ee.eng.hawaii.edu/Courses/EE150/Book/
I would not recommend this one. In the first C program it used the very
old fashioned definition of main:
main()
{
}

Hardly a killer. After all, K&R2 does this as well.
I agree. If all that was wrong was a few old fashioned definitions it
would be worth pointing out but would not be a reason to avoid it.
>It failed to #include <stdio.hbefore using printf.

That's rather more serious. Taken with the other issues you mentioned, it's
enough to scupper any tutorial.
Which is why I considered a brief critique worth the effort.

What makes it worse is it is apparently a course that was run at this
educational establishment in the spring of 98. I was about to say that a
later course was a bit better although still having a lot of old
fashioned and out of date stuff for a course in 2006, then I looked more
carefully and saw this
http://www-ee.eng.hawaii.edu/~tep/EE...00000000000000
To be fair, some of the rest of it is not so bad and I saw several
examples that did include stdlib.h. However, then we get to
http://www-ee.eng.hawaii.edu/~tep/EE...00000000000000
which says amongst other things:
| ... If the array is an integer array, (float array, character array,
| etc.) then the type of X is int * ( float *, char *, etc.). Thus,
| the declaration of an array causes the compiler to allocate the
| specified number of contiguous cells of the indicated type, as well as
| to allocate an appropriate pointer cell, initialized to point to the
| first cell of the array. This pointer cell is given the name of the
| array.
Then I think, well, that kind of teaching could explain all the effort
people have to go in to on this group to explain the difference between
pointers and arrays.

Some of it is not too bad, but you *really* don't want to know some of
the rest of what I saw.
<snip>
>>http://computer.howstuffworks.com/c.htm/
I can't recommend this either. This started off looking better until it
suggested using gets in real programs

Ouch!
To be fair it mentioned fgets in the same sentence, but did not
recommend it over fgets.
>The comp.lang.c FAQ, K&R2 (see the bibliography of the comp.lang.c FAQ)
and many other books that have been recommended here would be far better.

See also:

* http://www.eskimo.com/~scs/cclass/
* http://cprog.tomsweb.net/cintro.html
Your recommendations, on the other hand, I feel no need to check myself
for suitability. Your recommendation would be enough even if I did not
recognise who wrote the first tutorial from the URL.
--
Flash Gordon
Nov 1 '06 #14
Bertram Trabant wrote:
Roland Pibinger wrote:
>On 31 Oct 2006 04:09:24 -0800, "Bertram Trabant"
.... snip ...
>
>2. Read the whole or parts (e.g. single lines) of the file into a
string and search the string. For that you need malloc and free for
(de-)allocation (or a fixed size buffer), the aforementioned stdio
functions and strstr to find the substring.

This looks good. Do commands like getc() use some sort of "cursor" in
the file? That would be a huge time-saver (Stupid code, clever file).
To search for a single string you don't need any buffers. See the
following little demonstration to search for a string in a stream
without backtracking.

/*
Leor Zolman wrote:
On 25 Feb 2004 07:34:40 -0800, jo**@ljungh.se (spike) wrote:
>Im trying to write a program that should read through a binary
file searching for the character sequence "\name\"

Then it should read the characters following the "\name\"
sequence until a NULL character is encountered.

But when my program runs it gets a SIGSEGV (Segmentation
vioalation) signal.

Whats wrong? And is there a better way than mine to solve
this task (most likely)

I think so. Here's a version I just threw together:
*/

/* And heres another throw -- binfsrch.c by CBF */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>

/* The difference between a binary and a text file, on read,
is the conversion of end-of-line delimiters. What those
delimiters are does not affect the action. In some cases
the presence of 0x1a EOF markers (MsDos) does.

This is a version of Knuth-Morris-Pratt algorithm. The
point of using this is to avoid any backtracking in file
reading, and thus avoiding any use of buffer arrays.
*/

size_t chrcount; /* debuggery, count of input chars, zeroed */

/* --------------------- */

/* Almost straight out of Sedgewick */
/* The next array indicates what index in id should next be
compared to the current char. Once the (lgh - 1)th char
has been successfully compared, the id has been found.
The array is formed by comparing id to itself. */
void initnext(int *next, const char *id, int lgh)
{
int i, j;

assert(lgh 0);
next[0] = -1; i = 0; j = -1;
while (i < lgh) {
while ((j >= 0) && (id[i] != id[j])) j = next[j];
i++; j++;
next[i] = j;
}
#if (0)
for (i = 0; i < lgh; i++)
printf("id[%d] = '%c' next[%d] = %d\n",
i, id[i], i, next[i]);
#endif
} /* initnext */

/* --------------------- */

/* reads f without rewinding until either EOF or *marker
has been found. Returns EOF if not found. At exit the
last matching char has been read, and no further. */
int kmpffind(const char *marker, int lgh, int *next, FILE *f)
{
int j; /* char position in marker to check */
int ch; /* current char */

assert(lgh 0);
j = 0;
while ((j < lgh) && (EOF != (ch = getc(f)))) {
chrcount++;
while ((j >= 0) && (ch != marker[j])) j = next[j];
j++;
}
return ch;
} /* kmpffind */

/* --------------------- */

/* Find marker in f, display following printing chars
up to some non printing character or EOF */
int binfsrch(const char *marker, FILE *f)
{
int *next;
int lgh;
int ch;
int items; /* count of markers found */

lgh = strlen(marker);
if (!(next = malloc(lgh * sizeof *next))) {
puts("No memory");
exit(EXIT_FAILURE);
}
else {
initnext(next, marker, lgh);
items = 0;
while (EOF != kmpffind(marker, lgh, next, f)) {
/* found, take appropriate action */
items++;
printf("%d %s : \"", items, marker);
while (isprint(ch = getc(f))) {
chrcount++;
putchar(ch);
}
puts("\"");
if (EOF == ch) break;
else chrcount++;
}
free(next);
return items;
}
} /* binfsrch */

/* --------------------- */

int main(int argc, char **argv)
{
FILE *f;

f = stdin;
if (3 == argc) {
if (!(f = fopen(argv[2], "rb"))) {
printf("Can't open %s\n", argv[2]);
exit(EXIT_FAILURE);
}
argc--;
}
if (2 != argc) {
puts("Usage: binfsrch name [binaryfile]");
puts(" (file defaults to stdin text mode)");
}
else if (binfsrch(argv[1], f)) {
printf("\"%s\" : found\n", argv[1]);
}
else printf("\"%s\" : not found\n", argv[1]);
printf("%lu chars\n", (unsigned long)chrcount);
return 0;
} /* main binfsrch */

--
Some informative links:
<news:news.announce.newusers
<http://www.geocities.com/nnqweb/>
<http://www.catb.org/~esr/faqs/smart-questions.html>
<http://www.caliburn.nl/topposting.html>
<http://www.netmeister.org/news/learn2quote.html>
<http://cfaj.freeshell.org/google/>
Nov 1 '06 #15
Richard Heathfield <in*****@invalid.invalidwrites:
Bertram Trabant said:
>pete napísal(a):
>>They use a "file position indicator",
if that's what you mean.

This looks promising, is there any way of directly controlling it?

Look up ftell, fseek, fgetpos, and fsetpos.
And don't expect them to work on anything other than disk files. You
can't rewind a keyboard.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 1 '06 #16
In article <45***********@mindspring.com>,
pete <pf*****@mindspring.comwrote:
>Bertram Trabant wrote:
>Do commands like getc() use some sort of "cursor" in
the file?
>They use a "file position indicator",
if that's what you mean.
I'd forgotten that term was used in the standard.
I noticed something interesting (but not much related to the original
quesiton) when I re-read the C89 section today, and I don't recall seeing
it before: that the actual address of a FILE object may be significant
and that a copy of the FILE object "may not necessarily serve"
in place of the original. It makes a certain kind of sense in practice,
allowing the implementation some optimizations in linking FILE objects
and implementation-level "underlying functions" such as read().
--
"law -- it's a commodity"
-- Andrew Ryan (The Globe and Mail, 2005/11/26)
Nov 1 '06 #17
Walter Roberson wrote:
In article <45***********@mindspring.com>,
pete <pf*****@mindspring.comwrote:
Bertram Trabant wrote:
Do commands like getc() use some sort of "cursor" in
the file?
They use a "file position indicator",
if that's what you mean.

I'd forgotten that term was used in the standard.
I noticed something interesting (but not much related to the original
quesiton) when I re-read the C89 section today, and I don't recall seeing
it before: that the actual address of a FILE object may be significant
and that a copy of the FILE object "may not necessarily serve"
in place of the original. It makes a certain kind of sense in practice,
allowing the implementation some optimizations in linking FILE objects
and implementation-level "underlying functions" such as read().
I started a thread on this some time ago:
http://groups.google.co.uk/group/com...a89169bf8c624d

Nov 1 '06 #18
On Wed, 01 Nov 2006 11:06:34 +0000, Flash Gordon
<sp**@flash-gordon.me.ukwrote:
>Roland Pibinger wrote:
>You may have a look at an introductionary C book or an online tutorial
like:
http://www-ee.eng.hawaii.edu/Courses/EE150/Book/

I would not recommend this one.
>http://computer.howstuffworks.com/c.htm/

I can't recommend this either.
IMO, for the student accessibility of the content and the right 'pace'
are more important than 100% correctness.

Best regards,
Roland Pibinger
Nov 1 '06 #19
Keith Thompson said:
Richard Heathfield <in*****@invalid.invalidwrites:
>Bertram Trabant said:
>>pete napísal(a):
They use a "file position indicator",
if that's what you mean.

This looks promising, is there any way of directly controlling it?

Look up ftell, fseek, fgetpos, and fsetpos.

And don't expect them to work on anything other than disk files. You
can't rewind a keyboard.
Oh yes you can. It's messy, but it can be done. (I wouldn't count on being
able to type on it afterwards, though.)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Nov 1 '06 #20
Flash Gordon said:

<snip>
>
To be fair it mentioned fgets in the same sentence, but did not
recommend it over fgets.
Tough crowd. :-)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Nov 1 '06 #21
rp*****@yahoo.com (Roland Pibinger) writes:
On Wed, 01 Nov 2006 11:06:34 +0000, Flash Gordon
<sp**@flash-gordon.me.ukwrote:
>>Roland Pibinger wrote:
>>You may have a look at an introductionary C book or an online tutorial
like:
http://www-ee.eng.hawaii.edu/Courses/EE150/Book/

I would not recommend this one.
>>http://computer.howstuffworks.com/c.htm/

I can't recommend this either.

IMO, for the student accessibility of the content and the right 'pace'
are more important than 100% correctness.
There is no reason, and no excuse, for a tutorial not to be correct as
well as accessible and properly paced.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 1 '06 #22
On Wed, 2006-11-01 at 17:11 +0000, Flash Gordon wrote:
Richard Heathfield wrote:
The comp.lang.c FAQ, K&R2 (see the bibliography of the comp.lang.c FAQ)
and many other books that have been recommended here would be far better.
See also:

* http://www.eskimo.com/~scs/cclass/
* http://cprog.tomsweb.net/cintro.html

Your recommendations, on the other hand, I feel no need to check myself
for suitability. Your recommendation would be enough even if I did not
recognise who wrote the first tutorial from the URL.
Perhaps you should. I've never seen an error Richard Heathfield made
that someone else caught (with the exception of Keith Thompson, who
seems to see everything), simply because his clout in this group makes
everyone assume he's right.

I'm not suggesting that these links in particular are wrong, nor am I
suggesting that he makes errors on this group more than once in a blue
moon. I'm just saying that we should still be wary. ;-)

--
Andrew Poelstra <http://www.wpsoftware.net>
For email, use 'apoelstra' at the above site.
"You're only smart on the outside." -anon.

Nov 2 '06 #23
Roland Pibinger wrote:
On Wed, 01 Nov 2006 11:06:34 +0000, Flash Gordon
<sp**@flash-gordon.me.ukwrote:
>Roland Pibinger wrote:
>>You may have a look at an introductionary C book or an online tutorial
like:
http://www-ee.eng.hawaii.edu/Courses/EE150/Book/
I would not recommend this one.
>>http://computer.howstuffworks.com/c.htm/
I can't recommend this either.

IMO, for the student accessibility of the content and the right 'pace'
are more important than 100% correctness.

Best regards,
Roland Pibinger
I really don't understand you. Correctness takes precedence over
everything else in any sort of tutorial, surely.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 2 '06 #24
Roland Pibinger wrote:
On Wed, 01 Nov 2006 11:06:34 +0000, Flash Gordon
<sp**@flash-gordon.me.ukwrote:
>Roland Pibinger wrote:
>>You may have a look at an introductionary C book or an online tutorial
like:
http://www-ee.eng.hawaii.edu/Courses/EE150/Book/
I would not recommend this one.
>>http://computer.howstuffworks.com/c.htm/
I can't recommend this either.

IMO, for the student accessibility of the content and the right 'pace'
are more important than 100% correctness.
In my opinion, something that is just plain wrong is *far* worse than
nothing at all. The links that you posted have a lot that is just plain
wrong such as the things I pointed out. I did not have to go that far on
them to find enough problems to make them worse than useless.
--
Flash Gordon
Nov 2 '06 #25
Andrew Poelstra wrote:
On Wed, 2006-11-01 at 17:11 +0000, Flash Gordon wrote:
>Richard Heathfield wrote:
<snip>
>Your recommendations, on the other hand, I feel no need to check myself
for suitability. Your recommendation would be enough even if I did not
recognise who wrote the first tutorial from the URL.

Perhaps you should. I've never seen an error Richard Heathfield made
that someone else caught (with the exception of Keith Thompson, who
seems to see everything), simply because his clout in this group makes
everyone assume he's right.
I agree completely with you and in general do my best to spot any errors
made by any of the regulars as well as names I don't recognise. One of
the good things about this group is that no matter how well respected
someone is if they make a mistake someone will point it out and the
better posters will accept the corrections.
I'm not suggesting that these links in particular are wrong, nor am I
suggesting that he makes errors on this group more than once in a blue
moon. I'm just saying that we should still be wary. ;-)
Indeed.
--
Flash Gordon
Nov 2 '06 #26
2006-11-02 <L8******************************@comcast.com>,
Joe Wright wrote:
Roland Pibinger wrote:
>On Wed, 01 Nov 2006 11:06:34 +0000, Flash Gordon
<sp**@flash-gordon.me.ukwrote:
>>Roland Pibinger wrote:
You may have a look at an introductionary C book or an online tutorial
like:
http://www-ee.eng.hawaii.edu/Courses/EE150/Book/
I would not recommend this one.

http://computer.howstuffworks.com/c.htm/
I can't recommend this either.

IMO, for the student accessibility of the content and the right 'pace'
are more important than 100% correctness.

Best regards,
Roland Pibinger

I really don't understand you. Correctness takes precedence over
everything else in any sort of tutorial, surely.
I'd say that simplification early on is okay (a tutorial on physics
could start with newtonian mechanics for example, despite the fact that
they are manifestly incorrect), but out-and-out _wrong_ information is
different. The line is hard to draw, though.
Nov 2 '06 #27
Andrew Poelstra said:
On Wed, 2006-11-01 at 17:11 +0000, Flash Gordon wrote:
>Richard Heathfield wrote:
>
See also:

* http://www.eskimo.com/~scs/cclass/
* http://cprog.tomsweb.net/cintro.html

Your recommendations, on the other hand, I feel no need to check myself
for suitability. Your recommendation would be enough even if I did not
recognise who wrote the first tutorial from the URL.

Perhaps you should. I've never seen an error Richard Heathfield made
that someone else caught (with the exception of Keith Thompson, who
seems to see everything),
Not so. I've been corrected on very many occasions. Less so in recent years,
I suppose, but only because I don't make quite so many blunders as I used
to. But I still make 'em from time to time, and I still welcome corrections
when I do.
simply because his clout in this group makes everyone assume he's right.
That doesn't even apply to Chris Torek, who has far more "clout" in this
group than I do (and rightly so).
I'm not suggesting that these links in particular are wrong, nor am I
suggesting that he makes errors on this group more than once in a blue
moon. I'm just saying that we should still be wary. ;-)
Right! So... if you're wary (as you should be), go and look, and do the
usual check for the obvious screw-ups. I'd be surprised if you find any,
but use your own eyes, not mine. (I'd also be surprised if you *didn't*
find at least one non-obvious screw-up, if you spend long enough looking.
After all, everyone's human...)

One of the tutorials, incidentally, is by Steve Summit, who needs no
introduction. The other is by Tom Torfs, who was a longstanding member of
this group until he disappeared in mysterious circumstances after asking a
question about C99's changes to the preprocessor spec. Missing, presumed
writing a C99 compiler.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Nov 2 '06 #28
On 31 Oct 2006 04:09:24 -0800, "Bertram Trabant"
<ni**********@gmail.comwrote:
>Hello, Im working on a little LAN game in the style of old text-only
MUD's and would need to find a way to search for a string in a text
file (for example for usernames). I know it works in the way of looking
for the first letter, if matches the second and so on, but don't know
how to write it. Any suggestions?
Call a file filter or a perl script from within your C program.

Andreas
-------
1 + 1 = 3, for large values of 1.
Nov 2 '06 #29
rp*****@yahoo.com (Roland Pibinger) writes:
IMO, for the student accessibility of the content and the right 'pace'
are more important than 100% correctness.
If the information is incorrect -- as opposed to "we won't explain
this fully right now, but trust us, we'll get to it later" -- then the
accessibility of the content and the right pacing are completely
irrelevant.

Learn incorrect material now because it's easy, and spend a lot more
effort unlearning and relearning later, if you ever get that far.

Charlton

Nov 2 '06 #30
Andreas Kochenburger wrote:
On 31 Oct 2006 04:09:24 -0800, "Bertram Trabant"
<ni**********@gmail.comwrote:
Hello, Im working on a little LAN game in the style of old text-only
MUD's and would need to find a way to search for a string in a text
file (for example for usernames). I know it works in the way of
looking for the first letter, if matches the second and so on, but
don't know how to write it. Any suggestions?

Call a file filter or a perl script from within your C program.
Why would you deliberately introduce non-portable elements when they
aren't necessary?


Brian
Nov 2 '06 #31
I'd like to thank everyone who helped (resp. argued), i found the bugs
in my code. They didn't have anything to do with the string, i just
wrote the conditions wrong, but anyways thanks for the effort.

(Now you can stop the flame war about tutorials:)

Nov 3 '06 #32
On 2 Nov 2006 19:00:49 GMT, "Default User" <de***********@yahoo.com>
wrote:
>Why would you deliberately introduce non-portable elements when they
aren't necessary?
Why are embedded interpreters - e.g. Lua - so useful ?

Andreas
-------
1 + 1 = 3, for large values of 1.
Nov 3 '06 #33


On Oct 31, 12:09 pm, "Bertram Trabant" <niektonie...@gmail.comwrote:
Hello, Im working on a little LAN game in the style of old text-only
MUD's and would need to find a way to search for a string in a text
file (for example for usernames). I know it works in the way of looking
for the first letter, if matches the second and so on, but don't know
how to write it. Any suggestions?
If your text file is a list of account details stored on disk, indexed
by user-name, and there are potentially many users, then it might be
better, and easier, to use a database such as SQL (MySQL is a free
version) (which might use an O(log n) b-tree or b+tree algorithm for
indexes - Knuth-Pratt-Morris algorithm is a linear algorithm O(n+m)
where n is the length of the file, and m is the length of the
search-string) - big O notation is a way that computer scientists
classify the efficiency of algorithms as n gets larger - the n in O(log
n) in b-tree or b+tree search which, if I have guessed right in your
case, is the number of accounts - a database using b-tree or b+tree
algorithm will be more efficient than linear string searching when n is
large (i.e. large number of accounts).

Nov 3 '06 #34

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

Similar topics

10
by: Anand Pillai | last post by:
To search a word in a group of words, say a paragraph or a web page, would a string search or a regexp search be faster? The string search would of course be, if str.find(substr) != -1:...
4
by: Ken Fine | last post by:
I'm looking to find or create an ASP script that will take a string, examine it for a search term, and if it finds the search term in the string, return the highlighted search term along with the...
4
by: Jason Gleason | last post by:
What's the most efficient way to get the number of occurences of a certain string in another string..for instance i'm using the following code right now... private int CharacterCounter(String...
60
by: Julie | last post by:
What is the *fastest* way in .NET to search large on-disk text files (100+ MB) for a given string. The files are unindexed and unsorted, and for the purposes of my immediate requirements, can't...
15
by: Chuck Bowling | last post by:
I'm having problems doing an efficient keyword search on a text file likely to be smaller than 100k. I have a keyword list of about 200 strings and I need to search the file and mark all of the...
4
by: Nikos | last post by:
Hi... I would like to search for a hex string (for example: "E903") inside a binary file... Although I open the file correctly, how do I search hex values? Thanks in advance! Nikos
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
3
by: Imran Aziz | last post by:
Hello All, I am getting the following error on our production server, and I dont get the same error on the development box. Unable to cast object of type 'System.Byte' to type 'System.String'. ...
21
by: gary | last post by:
How would one make the ECMA-262 String.replace method work with a string literal? For example, if my string was "HELLO" how would I make it work in this instance. Please note my square...
14
by: S | last post by:
Any idea on how I would be able to do a search within C# that does ranges or words For example I want to search for Chicken in the string string s1 = "This is Great Chicken";
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.