Re: Way around error?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Balboos (balboos_at_masonicbrother.com.No.Spam)
Date: 05/03/04


Date: Mon, 03 May 2004 10:19:55 GMT

Thank you both for the confirmation that it's just not going to happen.

The hope was to design a method that was 'universal' - since the string
never changes length, this would be possible safely "in theory." It
shouldn't be needed for const char * (as initialized for failure), since
  the programmer should create the constant correctly.

Even in 'C', you can't have it all;

Thanks, again,
Balboos

Balboos wrote:
> Hi, all.
>
> I'm making a number of function overloads for a 'capitlizing' function,
> it's purpose to convert an input string to mixed upper and lower case as
> though it were (for example) a name. The (char *) version's giving me
> some grief. The code (below) works if the string is allocated from the
> heap, but not from the stack (access violation).
>
> i.e., if I use:
> char instring[9] = "john doe";
> I get back "John Doe".
>
> If I use
> char *instring = "john doe";
> I get the access violation at the first attempt to modify the string.
> Similarly, if I call the function with the text as the argument.
> i.e., Capitalize("john doe"), it crashes.
>
> // SOURCE
> char *Capitalize(char *instring) {
>
> char *tmp; // for copy of pointer to input char string.
> bool needUC=true; // set if we 'need' to make next alpha UC; else LC
>
> if(instring!=NULL) {
> strlwr(instring); // Start out all LC - ACCESS VIOLATION!
> for(tmp=instring; *tmp; ++tmp) {
> if(!isalpha(*tmp)) {
> needUC = true; // We've hit a non-alpha - set UC flag
> continue;
> } // if(!isalpha(*tmp))
> if(needUC) {
> *tmp = toupper(*tmp);
> needUC = false; // set flag that UC is satisfied
> } // if(needUC)
> } // while(tmp=instring; *tmp; ++tmp)
> } // if(instring!=NULL)
>
> return instring;
> } // char *Capitalize(char *instring)
>
> Is there a way around this?
>
> Balboos
>



Relevant Pages

  • Re: Fortran-compiled DLLs in Python
    ... WindowsError: exception: access violation ... > I do not know how fortran passes this parameter, ... strings may pass a "string descriptor", ...
    (comp.lang.python)
  • Re: Way around error?
    ... The code works if the string is allocated from the ... attempted to convert a const value to a non-const pointer. ... >I get the access violation at the first attempt to modify the string. ... MVP Tips: http://www.flounder.com/mvp_tips.htm ...
    (microsoft.public.vc.mfc)
  • AnsiString on Heap.
    ... AnsiString is inside the form. ... If no string is assigned to it it will still give an access violation making ...
    (alt.comp.lang.borland-delphi)
  • Re: Getting rid of access violation message
    ... A better solution is to correct the problem rather than kill the messenger, ... set the Reg_Sz string value ... Windows Server 2003 or later) so that if a program produces an access violation, that the AV will not be shown, i.e. the program just ends without an error dialog being shown? ...
    (microsoft.public.windows.server.general)
  • Re: Inline Assembly
    ... your stosb writes to *StringWorked, you're getting an access violation. ... Presumably you mean to do some kind of transform on the string while copying ... writing this code in C or C++, and it'll be less portable and a lot less ...
    (microsoft.public.vc.language)