Re: Delimiting problems

From: Zoran Cutura (zoran.cutura_at_daimlerchrysler.com)
Date: 04/01/04


Date: 1 Apr 2004 14:06:54 GMT

Ess355 <ess355@hotmail.com> wrote:
> Thanks for your help people, and yes I'm only a novice, please forgive
> me. :-)
>
> Got Q1 and Q2 sorted thanks.
>
> I just have two more questions (what are simple again so it should
> take no time in answering)... :-o
>
> text2=fopen(".\\Text_Files\\testingtemp.txt","r");
> while((fgets (string, 400, text2)) != NULL)
> {
> currentword = strtok(string," \t\r\n");
>
> Q4) In the above code, is it possible to make the path name changeable
> at run time? I'd like this in the hope that it would simplify my
> program so I can pass the file name through a function, e.g.
> opentemp(testingtemp.txt); (or is the syntax
> opentemp("testingtemp.txt"); ???? ) Is it possible to use a string
> variable to feed in the testingtemp.txt part to the pathname?

Actually "testingtemp.txt" is a string that is passed, or let me be mor
prcise it is the reference to the beginning of the string. You may pass
any king of reference to the beginning of some string that holds the
filename or whatever you are trying to use.

Say

char * filename = "the/file/to.open";
FILE *fp = fopen(filename, "r");

is equivalent to

FILE *fp = fopen("the/file/to.open", "r");

Or if you want the file name to be read at runtime something along:

#define do_str(x) #x
#define str(x) do_str(x)
char filename[FILENAME_MAX];
FILE *fp;

fputs("which file? >", stdout);
scanf("%" str(FILENAME_MAX) "[^\n]", filename);
getchar();

fp = fopen(filename, "r");
...

>
> Q5) Another delimiter question, soz...
>
> ...
> const char delimiters[] = "\" .,;:!,\r\n\t()";
> ...
> currentword = strtok(string,delimiters);
> while(currentword!='\0')
> {
> countwords++;
> ...
>
> What is the above code to delimit new lines before characters? E.g.

I don't understand!

>
> Hi
> Bye
> Go
>
> Would be read as 5 words instead of 3.
>
> And is it possible for an explanation with the NULL character why the
> above delimiter counts new lines even though I've used the "\n" code?
>
> Thanks in advance.
> Ess

HTH, HAND

-- 
Z (Zoran.Cutura@daimlerchrysler.com)
"LISP  is worth learning for  the profound enlightenment  experience
you will have when you finally get it; that experience will make you
a better programmer for the rest of your days."   -- Eric S. Raymond 


Relevant Pages

  • Re: Instrrev function
    ... then goes totwo characters. ... So to get the column reference ... Hope this is noted by Microsoft. ... "Returns the position of an occurrence of one string within another, ...
    (microsoft.public.excel.programming)
  • Re: how to compare a null string
    ... The correct way to compare one String with another is through the method ... reference to some other String object with zero or more characters. ...
    (comp.lang.java.programmer)
  • Re: STL Slow - VS2005
    ... accurately this benchmark represents real-world workloads. ... People have done quite a few studies on string lengths as they're ... quickly with length -- even 1000 characters is extremely rare. ... by reference, modify a string whose reference was passed. ...
    (microsoft.public.vc.stl)
  • Re: Getting Rid of the Nulls
    ... "If trimChars is a null reference, ... >> to converter a byte array from the registry to a string. ... but I end up with a bunch of null characters after ... >> The only thing I can think of is to convert the string to a char array ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Complex Specified Information - Pitman Formula
    ... Therefore a significant match between a reference and a test ... string is good evidence of non-random production. ... and there are no finite algorithms to compute their digits. ... probabilities of the different symbols the information source can produce. ...
    (talk.origins)