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.
45 messages · Page 1 of 1 (latest)
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.
I need to modify flexNum, thats what they want in the instructions
what you're essentially doing is something like "test"[1] = 'b'
and you can't modify string literals, they're read only
String literals are const
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
Are you required to have a string literal as an input?
Yea I can't edit the function declaration and I just copied over the tests they gave
char str[] = "0001020304050.000000";
flexNumStandardize(str));
now you could modify input string
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[]
The other approach would be to return a new char string
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?
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
idk tbh, i've been stuck on this error for a rly long time
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
Ill get back home and try to come up with something
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"
Yeah the exercise just doesnt really make sense for me, but thats me
Because as far as I know, string literals are immutable
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[]
Seems likely
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
Id expect it to, array parameters are cast down to pointers anyway as far as I know
Yeah modifying string literal is literally undefined behaviour, the way the program is shown to be called can't really be called
No it wouldn't work
This doesn't stack allocate memory it only references string literal which is read only
!solved
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