Re: Delimiting problems
From: Zoran Cutura (zoran.cutura_at_daimlerchrysler.com)
Date: 04/01/04
- Next message: Zoran Cutura: "Re: array with pointers....."
- Previous message: Jens.Toerring_at_physik.fu-berlin.de: "Re: Type casting- a larger type to a smaller type"
- In reply to: Ess355: "Re: Delimiting problems"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Zoran Cutura: "Re: array with pointers....."
- Previous message: Jens.Toerring_at_physik.fu-berlin.de: "Re: Type casting- a larger type to a smaller type"
- In reply to: Ess355: "Re: Delimiting problems"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|