Re: Delimiting problems
From: Mike Wahler (mkwahler_at_mkwahler.net)
Date: 03/31/04
- Next message: pete: "Re: Delimiting problems"
- Previous message: pete: "Re: Delimiting problems"
- In reply to: Ess355: "Delimiting problems"
- Next in thread: Malcolm: "Re: Delimiting problems"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 31 Mar 2004 17:16:41 GMT
"Ess355" <ess355@hotmail.com> wrote in message
news:aca2e945.0403310843.64e97881@posting.google.com...
> Hello all,
>
> I've got a simple problem and a harder problem. Simple one first:
>
> 1) I can't get the character " and as a delimiter.
>
> Here is what I have:
> ...
> const char delimiters[] = " .,;:!,\r\n\t()";
> ...
> currentword = strtok(string, delimiters);
>
> I've tried putting the " character in two ' characters to delimit the
> " character, but the compiler throws it out:
>
> const char delimiters[] = " .,;:!,\r\n\t()'"'";
>
> So how can I delimit the " character?
const char delimiters[] = "\" .,;:!,\r\n\t()";
>
> 2) I'm trying to count the number of words and letters from a text
> file. Now when I have a piece of string such as
>
> government's
>
> I don't want the ' character because I'm using the strlen() function
> count the number of words only. If I delimit the ' character then the
> string gets split in two and the s on the end of the string becomes a
> separate word, i.e.
>
> government s
>
> So instead of counting one word, I'll count 2, which of course is
> inaccurate of my program.
>
> How can I get round these problems?
Don't use the ' as a delimiter. Extract your words,
and the search each for the ' character. If you
find one, replace it with a zero, which will truncate
the string.
-Mike
>
> Thanks in advance :-)
> Ess
>
> PS: And just for experimenting purposes:
>
> 3) I want to filter out some words, this method doesn't seem to work,
> even though it compiles alright:
> ...
> c = fgetc (TextFile);
> if (c=!('!'||' '||'.'||'\0')) n++;
This isn't doing what you probably think. It's
If you want to compare against several values,
you must write each comparison separately:
if(c != '!' && c != ' ' && c != '.' && c != 0)
n++;
The expression:
('!'||' '||'.'||'\0')
has a single value (always true), so your
above statement always evaluates to false
(due to your use of the ! operator). Note
that you've also assigned this 'false' value
to 'c'. (I think you meant to write == instead
of =.
(due to the ! operator you used.
> I am try to avoid the characters .! etc. The program hangs when I try
> it.
If you use those characters as your strtok() delimiters,
they'll be excluded.
>
> However when I tried this, it worked.
>
> ...
> c = fgetc (TextFile);
> if (c==A) n++;
> ...
>
> Which would count the number of A's in the string.
>
> I'm confused :-)
Perhaps. You're also not being careful enough. :-)
Write a much smaller program, outputting the results
from e.g. your comparsions, so you'll better understand
how all these operators work.
-Mike
- Next message: pete: "Re: Delimiting problems"
- Previous message: pete: "Re: Delimiting problems"
- In reply to: Ess355: "Delimiting problems"
- Next in thread: Malcolm: "Re: Delimiting problems"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|