#Help with Access Violation Error

45 messages · Page 1 of 1 (latest)

glass oakBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

tidal kite
#

you can't modify those

#

you'd need to copy the string into a char array

wise meteor
#

I need to modify flexNum, thats what they want in the instructions

tidal kite
#

what you're essentially doing is something like "test"[1] = 'b'

#

and you can't modify string literals, they're read only

wise meteor
#

isnt it a char* tho?

#

So its just an array of chars

true kindle
#

String literals are const

wise meteor
#

I see, so is there anyway I can edit flexNum that would work? Because its required I edit flexNum.

#

The instructions say "Modify flexNum", so I assumed I could do this

true kindle
#

Are you required to have a string literal as an input?

wise meteor
#

Yea I can't edit the function declaration and I just copied over the tests they gave

tidal kite
#
char str[] = "0001020304050.000000";
flexNumStandardize(str));
#

now you could modify input string

wise meteor
#

Is there anyway to modify it as a char*, cause I'm not allowed to change the tests or the decleration to make it a char str[]

true kindle
#

The other approach would be to return a new char string

wise meteor
#

I have to return like "codes" depending on what I do. I can only return 0,1,2

#

and they expect you to edit flexNum

#

So I asssume it has to be possible somehow?

true kindle
#

I feel like you're not expected to put string literals in the function

#

Think about it, you are editing a string and return a return code, what would even be the point of trying to standartize a string literal

wise meteor
#

my code seems like the algorithms work, but it just errors out

#

So i'm trying to figure out a way to be able to edit flexNum

true kindle
#

Ill get back home and try to come up with something

wise meteor
#

Maybe the tests are missleading? cause what you say does have merit

#

it would be kinda dumb to give a string literal and then say "edit it"

true kindle
#

Yeah the exercise just doesnt really make sense for me, but thats me

#

Because as far as I know, string literals are immutable

wise meteor
#

yea, honestly they might be missleading by writing that test out

#

they might've written the test like that for simplicity

#

but expected you to change it using char arr[]

true kindle
#

Seems likely

wise meteor
#

Quick question though

#

If i ran the test like this:

#
char* str = "0001020304050.000000";
flexNumStandardize(str));```
#

Would that work?

#

The example above was with str[], but I'm wondering if I passed it with char* instead

true kindle
#

Id expect it to, array parameters are cast down to pointers anyway as far as I know

true kindle
tidal kite
#

This doesn't stack allocate memory it only references string literal which is read only

wise meteor
#

!solved

glass oakBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity