Re: Delimiting problems

From: Mike Wahler (mkwahler_at_mkwahler.net)
Date: 03/31/04


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



Relevant Pages

  • Re: searching for the highest index within a directory
    ... (I used to write code in the Ada programming language... ... Because "testFile_34" is a string, ... there is no way to compare them as numbers. ... means we look at the first character in each string. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: ADO Recordset FIND problem
    ... That is the only character that can be confused with a string ... Keep in mind, if you use a double quote as a string delimiter, ... if you wish to use double quotes to delimit ...
    (microsoft.public.scripting.vbscript)
  • Re: Quandry with the following C code (Intermediate)
    ... It doesn't do a compare the usual way. ... a string with Unicode characters over 256 in it. ... This tallies the number of occurrences of each separate character value ... of the same character at all in the first string, ...
    (comp.lang.c)
  • Re: String Comparison
    ... own selection filter for an external application. ... be able to compare a string to a value in much the same way a search ... Which would be compared with a string and return true if the string ... the string character by character to extract the information? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Numbers higher but the computer dosnt think so
    ... You haven't shown us how L is declared (String, Integer, Single, etc.). ... ASCII characters and String comparisons are done character by character. ... decide on how to compare these dissimilar things. ... also use the CDbl function to make the comparison, ...
    (comp.lang.basic.visual.misc)