>Hi,
>
>I'm not strong enough with C++ to judge it, but maybe C++ strings do
>have an overloaded == operator.
of course they do.
>Otherwise I would suggest to use the strcmp() function, maybe in
>conjunction with toupper() or tolower() if you want to compare the
>file names regardless of uppercase and lowercase writing.
>
>This means:
>Suppose you have your file names stored in two variables like these:
>
> #define MAX_NAME_LEN (1<<9)
> ...
> char FileName1 [MAX_NAME_LEN], FileName2 [MAX_NAME_LEN];
> ...
>
> // sooner or later the two variables contain the file names.
>
>Now in order to compare the file names, do this:
>
> if (strcmp( FileName1, FileName2))
> { // They are not equal.
> }
> else
> { // It's the same name!
> }
>
>If you want to compare without caring for uppercase and lowercase
>letters, you may use this one:
>
> char Name_1_Lower [MAX_NAME_LEN], Name_2_Lower [MAX_NAME_LEN];
> char ch;
> size_t Index;
> ...
>
> // Now we initialise the two lowercase names:
> for (Index = 0; (ch = FileName1 [Index]); Index++)
> Name_1_Lower [Index] = tolower( ch);
> Name_1_Lower [Index] = '\0';
> for (Index = 0; (ch = FileName2 [Index]); Index++)
> Name_2_Lower [Index] = tolower( ch);
> Name_2_Lower [Index] = '\0';
>
> // And now check the names:
> if (strcmp( Name_1_Lower, Name_2_Lower))
> {
> // The names do not match.
> }
> else
> {
> // It's the same file name!
> }
>
>Hope you get the idea. If you don't understand something, ask again.
>
>BTW if you will work solely under Windows for the rest of your life,
>you may use the stricmp() function; this is a strcmp() derivative
>which takes care of uppercase and lowercase letters considered
>identical.
>
>[Hope that no one will now scream out loud in pain because I've made
>a terrible mistake... :-) ]
>
>Regards,
>Nico
>
>--- In [EMAIL PROTECTED], Michael White <[EMAIL PROTECTED]>
>wrote:
> >
> >
> > aavvee <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > In my program, I created a file. Then I get a file name from
>inline command.
> > And I want to compare if this file name is the same as the file
>which I
> > created. How to do this? Thanks a lot!
> >
> > Best,
> >
> > Avee
> >
> > My suggestion, would be assign the name of the first file to a
>variable, and then the second file to a second variable. Then do
>an 'if' statement to compare them...
> >
> > if (var1 == var2)
> >
> >
> >
> > I'm new...so don't take too much strength in that idea. I'm still
>learning,...
>
>
>
>
>
>
>
>To unsubscribe, send a blank message to
><mailto:[EMAIL PROTECTED]>.
>Yahoo! Groups Links
>
>
>
>
Victor A. Wagner Jr. http://rudbek.com
The five most dangerous words in the English language:
"There oughta be a law"
To unsubscribe, send a blank message to <mailto:[EMAIL PROTECTED]>.
| Yahoo! Groups Sponsor | |
|
|
Yahoo! Groups Links
- To visit your group on the web, go to:
http://groups.yahoo.com/group/c-prog/
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
