Re: problem with function
From: Jack Klein (jackklein_at_spamcop.net)
Date: 10/23/04
- Next message: mobile Cephus: "deleting temp files"
- Previous message: James Connell: "Re: problem with function"
- In reply to: Colin Girling: "Re: problem with function"
- Next in thread: Colin Girling: "Re: problem with function"
- Reply: Colin Girling: "Re: problem with function"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 23 Oct 2004 13:58:31 -0500
On Sat, 23 Oct 2004 17:35:17 +0100, "Colin Girling"
<colin@colingirling.my-bulldog.com> wrote in
alt.comp.lang.learn.c-c++:
> Do you know what you have done?
More importantly, do you know what you have done? You have
top-posted, that is added your new material at the top with the quoted
post below. This makes technical discussions very hard to follow, and
is considered rude behavior in many technical discussion groups,
including this one.
When you post a response to another post, material you add belongs
after the quoted material that you are commenting on, as I have done
below. If you prefer to use Outlook Express for a newsreader, you can
either manually move to the bottom and add your material, or Google
for one of the patches that makes it work properly by default.
Or you can find another newsreader that doesn't ignore proper Internet
conventions, several good ones are free, including Free Agent and
Gravity.
> Firstly, newName = oldName only assigns the address of oldName to newName
> (does not copy the string).
> If you intended copying the string, you need to use the strcpy function.
> i.e.
> strcpy(newName, oldName);
>
> Also, you should pass a parameter into the function giving the string
> length.
> i.e. void changeFileName(char *oldName, char *newName, int iStrLen)
> Then you can check that you do not change memory past the end of the string.
> i.e. if( x+8 < iStrLen )
>
> Also, instead of assigning the chars to the end in the way you have, use the
> strcat function
> i.e.
> strcat(newName, ".sorted");
>
> Also, you could then test length like this:
> if( iStrLen < strlen(oldName) + strlen(".sorted") )
> strcat(newName, ".sorted");
This one is wrong, since strlen() does not count the terminating '\0'
in either character string. To have enough to concatenate two strings
you must have at least strlen(string) + strlen(string2) + 1 bytes.
> also, if you do this, set ".sorted" to a const char *.
> i.e.
> const char *pcszAppend = ".sorted";
> then
> strcat(newName, pcszAppend);
>
> Also, I suggest researching hungarian notation for variable names. Once you
Oh, no, certainly don't do that.
> get to grips with this, much easier to know what variable types are, and
> most of the industry using this also.
Most of the industry has realized that this is nonsense, and abandoned
it completely. It is useless noise that tends to hide the actual
meaning of variable names, assuming that variables are given
meaningful names to begin with. Many users of 'Hungarian' notation
don't. Perhaps they are too tired after typing all the prefix
characters.
My understanding is that even Microsoft has abandoned this now.
> Hungarian notation is where you prefix a variable name with a series of
> letters describing the data type.
>
> e.g.
> psz = point to char*
While I'm no expert on 'Hungarian', I am pretty sure you've several of
your examples wrong.
Isn't 'psz' a pointer a an array of characters containing a string?
'point to char*' would be a pointer to a pointer to char, not a
pointer to char.
> pcsz = point to const char *
Likewise here, I don't think 'pcsz' is proper 'Hungarian' for constant
pointer to a non constant pointer to characters.
> i = int
> l = long
> ul = unsigned long
> n = number (short, int or long, signed or unsigned)
> by = unsigned char
> c = char
> d = double
> etc...
You have completely missed the actual cause of the OP's problem. See
my response to the original post.
-- Jack Klein Home: http://JK-Technology.Com FAQs for comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html comp.lang.c++ http://www.parashift.com/c++-faq-lite/ alt.comp.lang.learn.c-c++ http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
- Next message: mobile Cephus: "deleting temp files"
- Previous message: James Connell: "Re: problem with function"
- In reply to: Colin Girling: "Re: problem with function"
- Next in thread: Colin Girling: "Re: problem with function"
- Reply: Colin Girling: "Re: problem with function"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|