HELP HELP HELP HELP HELP 
Author Message
 HELP HELP HELP HELP HELP


Bethell) felt inclined to write:

[who cares]

Here's a clue.  No one is going to feel inclined to respond to a
posting with nothing put repetitious Helps in the subject.  Secondly,
have you thought at all about looking at the FAQ before posting to
this group?  Keep in mind that there are hundreds of posts everyday
going through this group and that no one has time to read/respond to
them  all, so if you have a VALID point/question then you'd better get
down to it.

truly,
Marduk

______________________________________________________________
"AOL is like putting someone beind the wheel of a car with no
training and then telling us it's our fault if we don't get
out of the way."
                                         --Dave Fleck



Mon, 24 Nov 1997 03:00:00 GMT  
 HELP HELP HELP HELP HELP

I am still very new to C/C++ and am even newer to Visual C++, so please
feel free to laugh at my naievty...

I have a couple of problems which I would appreciate some help with:

1.  I need to scan a directory, looking for any files with a given
    extension.  Any which can be found are to have their names
    written to a disk file.

    I then need to scan each of the files identified by the above
    step (using the output file to which they were written as the driver
    for this step) for a string of text.  If this is found, replace the
    string with another.   Make a backup of any file which was updated.

2.  I found an example program in the Visual C++ help facility which might
    be adapted to help with the string search I require.  Unfortunately,
    I cannot understand it:

#include <search.h>
#include <string.h>
#include <stdio.h>

int compare (const void *arg1, const void *arg2);

void main( unsigned int argc, char **argv)
{
   char **result;
   char *key = "hello";

   result = (char **)_lfind(&key, argv, &argc, sizeof(char *), compare);

   if (result)
      printf ("%s found!\n", *result);
   else
      printf("hello not found!\n");

Quote:
}

int compare (const void *arg1, const void *arg2)
{
   return (_stricmp(*(char**)arg1, *(char**)arg2));

Quote:
}

        * - This is the program...

      ____
     //   \\  - ... this is a cloud...
      \__\/

        0    - ... and is my head :-(
       /|\
       / \

    Still with me?  I really hope so!

    Questions! questions!! questions!!!

    - The prototype for compare declares a couple of parameters:

      (const void *arg1, const void *arg2);

      Come again!!!

      What are these parameters saying/doing?

    - Why would argv be declared as a pointer to a pointer, and
      how is it being used?  result too???

    - the call to _lfind() is about the most confusing thing I have
      come accross so far with C.  Could someone please take the time
      to explain this call to me.  Specifically, why the addresses
      of key and argc are passed, why compare is part of the call, but
      especially, why there are no '()' or parameters with it.

    - Why do the two functions lfind and stricmp have a '_' prefixed to
      them?  Personally, I think they would look much prettier without
      it !!!! :-)

    - And finally, what's the story with those casts in the stricmp call?

Hopefully, someone can help me (email would be nice!!).  In the meantime,
I'll study them manuals and see what I can see....

Cheers folks!!
___ Blue Wave/QWK v2.12



Mon, 24 Nov 1997 03:00:00 GMT  
 HELP HELP HELP HELP HELP

Quote:

>I am still very new to C/C++ and am even newer to Visual C++, so please
>feel free to laugh at my naievty...

    No, we're laughing at your HELP HELP HELP subject line, which
we see about three times a week, always posted by clueless newbies.

Quote:
>I have a couple of problems which I would appreciate some help with:

>1.  I need to scan a directory, looking for any files with a given
>    extension.  Any which can be found are to have their names
>    written to a disk file.
>[more stuff deleted]

    There is no real way to do this with standard C (which, btw, is
the stated purpose of this group). However, you can try to look up
the functions opendir() and its ilk, which are more portable than
most. You seem to be programming under DOS/Windows; you may have
more luck with findfirst()/findnext().

Quote:
>2.  I found an example program in the Visual C++ help facility which might
>    be adapted to help with the string search I require.  Unfortunately,
>    I cannot understand it:

>[...]

>   result = (char **)_lfind(&key, argv, &argc, sizeof(char *), compare);

    _lfind() is not a standard C function; therefore, you're unlikely
to find help here. Try another newsgroup; comp.os.msdos.programmer
*might* help, although I'm a DOS programmer and haven't seen that one.
Perhaps it's specific to Visual C -- have you tried, say, the MANUAL??
Or, perhaps the TECH SUPPORT LINE?? Or maybe you're using the software
ILLEGALLY?? But hey, I digress.

Quote:

>    Still with me?  I really hope so!

    Your diagram (program/clouds/you) was cute :-)

Quote:
>    Questions! questions!! questions!!!

>    - The prototype for compare declares a couple of parameters:

>      (const void *arg1, const void *arg2);

>      Come again!!!
>      What are these parameters saying/doing?

    This declares arg1 and arg2 to be pointers to constant regions of
memory of unspecified type.

Quote:
>    - Why would argv be declared as a pointer to a pointer, and
>      how is it being used?  result too???

>    - the call to _lfind() is about the most confusing thing I have
>      come accross so far with C.  Could someone please take the time
>      to explain this call to me.  Specifically, why the addresses
>      of key and argc are passed, why compare is part of the call, but
>      especially, why there are no '()' or parameters with it.

    You'll have to consult your docs on this one -- _lfind() is
not a standard function. Quien sabe?

Quote:
>    - Why do the two functions lfind and stricmp have a '_' prefixed to
>      them?  Personally, I think they would look much prettier without
>      it !!!! :-)

    This is an often-used convention to indicate a non-standard
"system" function.... but it is only a convention.

--
----
Eric

"If anyone finds this offensive, I am prepared not only to retract my
words, but also to deny under oath that I ever said them." -- Tom Lehrer
----



Tue, 25 Nov 1997 03:00:00 GMT  
 HELP HELP HELP HELP HELP
-=> Quoting Marduk to All <=-



 Ma> Bethell) felt inclined to write:
 Ma>
 Ma>
 Ma> [who cares]

I cared, and so did a few other souls who were kind enough to post VALID
responses/comments.  I was most greatful to receive these.

 Ma> Here's a clue.  No one is going to feel inclined to respond to a
 Ma> posting with nothing put repetitious Helps in the subject.  Secondly,
 Ma> have you thought at all about looking at the FAQ before posting to
 Ma> this group?  Keep in mind that there are hundreds of posts everyday
 Ma> going through this group and that no one has time to read/respond to
 Ma> them  all, so if you have a VALID point/question then you'd better get
 Ma> down to it.

I was indeed aware of the number of posts here each day.  I was and am
also aware that there are many people here who pick which messages they
will read based upon the content of the subject headers.  Yes, the content
of my subject line probably was a bit much, but it did serve its intended
purpose by catching the attention of a few subscribers here.  I'll keep
the subject of any future posts toned down though.

I now have a copy of the FAQ.  Looks to be a great source of information,
so I'll be sure to consult it prior to posting here again.

Cheers

Andrew Bethell

Subject: char *ptr = "HELP HELP HELP"

___ Blue Wave/QWK v2.12



Wed, 26 Nov 1997 03:00:00 GMT  
 HELP HELP HELP HELP HELP

Bethell)says...
<< stuff deleted >>

My comments are within the source......

Quote:
>#include <search.h>
>#include <string.h>
>#include <stdio.h>

>int compare (const void *arg1, const void *arg2);

>void main( unsigned int argc, char **argv)
>{
>   char **result;
>   char *key = "hello";

>   result = (char **)_lfind(&key, argv, &argc, sizeof(char *), compare);

Look at the prorotype of _lsearch

void *_lsearch( const void *key, const void *base, unsigned int *num, unsigned int
width, int ( __cdecl *compare )( const void *elem1, const void *
elem2 ) );

Whar the call is doing is comaring the pointer to strings, but since the strings in
the argv are of different lengths, it is passing the pointer to the pointer to the
0th character of the string. This explains `&key`, and `argv`

`compare` in the prototype is declared as a pointer to the function taking `const
void *elem1 and `const void *elel2` as the two arguments and returning an integer.

The name of the function is the pointer to the function thus only `compare` is
passed because it is also the name of the function that will decide which string
pointer is to be considered large.

Quote:

>   if (result)

if result is non-NULL, "hello" was found.

If the result is

Quote:
>      printf ("%s found!\n", *result);
>   else
>      printf("hello not found!\n");
>}

>int compare (const void *arg1, const void *arg2)
>{
>   return (_stricmp(*(char**)arg1, *(char**)arg2));
>}

This function compares the strings pointed by the pointer pointed by arg1 and arg2
using the _stricmp (case insensitive compare).

<< some art deleted >>>

Quote:

>    Still with me?  I really hope so!

Yes

Quote:
>    Questions! questions!! questions!!!

>    - The prototype for compare declares a couple of parameters:

>      (const void *arg1, const void *arg2);

The `const` means that the arg1 is a pointer to a constant string i.e. the function
may not modify the strings.

Quote:

>      Come again!!!

>      What are these parameters saying/doing?

>    - Why would argv be declared as a pointer to a pointer, and
>      how is it being used?  result too???

this is necessary in this little example because we are actually passing pointers to
the string pointers to do the work for us. You will not have to pass ptr to ptr in
case you are comparing anything of fixed width, say long, or int

Quote:

>    - the call to _lfind() is about the most confusing thing I have
>      come accross so far with C.  Could someone please take the time
>      to explain this call to me.  Specifically, why the addresses
>      of key and argc are passed, why compare is part of the call, but
>      especially, why there are no '()' or parameters with it.

I discussed some of this up there. _lfind() does a linear search. Let me quote from
the MSVC manual :]

key     Object to search for
base    Pointer to base of search data
num     Number of elements
width   Width of elements
compare         Pointer to comparison routine
elem1   Pointer to the key for the search
elem2   Pointer to the array element to be compared with the key
The _lsearch function performs a linear search for the value key in an array of num
elements, each of width bytes in size. (Unlike bsearch, _lsearch does not require
the array to be sorted.) The base argument is a pointer to the base of the array to
be searched.
If key is not found, _lsearch adds it to the end of the array.

The compare argument is a pointer to a user-supplied routine that compares two array
elements and returns a value specifying their relationship. The _lsearch function
calls the compare routine one or more times during the search, passing pointers to
two array elements on each call. This routine must compare the elements, then return
one of the following values:

Value   Meaning
Nonzero Elements are different
0       Elements are identical
Return Value

If the key is found, _lsearch returns a pointer to the element of the array at base
that matches key. If the key is not found, _lsearch returns a pointer to the newly
added item at the end of the array.

Use _lsearch for compatibility with ANSI naming conventions of non-ANSI functions.
Use lsearch and link with OLDNAMES.LIB for UNIX compatibility.

Quote:

>    - Why do the two functions lfind and stricmp have a '_' prefixed to
>      them?  Personally, I think they would look much prettier without
>      it !!!! :-)

_stricmp() is a MSVC Small DATA model specific function which is (possibly)
optimized for 16 bit address. Also it does an case insensitive compare. It is
declared with the leading _.

Quote:

>    - And finally, what's the story with those casts in the stricmp call?

looka at the prototype of _stricmp() and you will realize that the function compare
receives pointers to pointers to void. you have pass pointers to char to _stricmp.
so.

Quote:

>Hopefully, someone can help me (email would be nice!!).  In the meantime,
>I'll study them manuals and see what I can see....

>Cheers folks!!
>___ Blue Wave/QWK v2.12

hope that helps....

mag
--
/*
To understand recursion one must first understand recursion
*/



Sat, 29 Nov 1997 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. HELP HELP HELP HELP HELP HELP!!!

2. HELP ++++++++++++++ HELP +++++++++++ HELP ++++++++++++++ HELP

3. OSP (Operating System Project) HELP HELP HELP HELP (files module)

4. HELP help HELP help

5. help VIRUS help help VIRUS help !

6. Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!

7. Help Help Help

8. Help ,Help <help , with my project

9. SOMEONE HELP ME, HELP ME, HELP ME PLEASE...

10. HELP HELP HELP ME PLEASE!!

11. HELP HELP HELP!!!

12. HELP HELP HELP!!!

 

 
Powered by phpBB® Forum Software