+ 1
【Solved】I have so many questions !!!! [JUST CHECK THE CODE & DISCUSSION]
note: as it is a sudo random code, you may need to run it multiple times to get the discoveries matched in some cases. a question besides the discoveries: Even if the string may contain junk values of the stack in the unused spaces, I'm only calling the for chars that has been filled with user input. Therfore, the junk values should not appear. then how? https://code.sololearn.com/cv3lh2C3vHHl/?ref=app
7 odpowiedzi
+ 3
No version of your code actually fulfills the specification written down at the top.
The difference between the array and the string is that a new[]-expression initializes the constructed object, so the array is filled with zero characters, which do not have a graphical representation. On the other hand, the string is likely empty and uninitialized (depends on the implementation), so the buffer contains actual garbage values. This means that with the array, you don't immediately "see" the incorrect behaviour.
You can verify this for versions you deemed correct by decreasing the iterations to a sensible value, e.g. ten, and counting the number of actually displayed characters.
The fundamental issue is that you request one character per iteration instead of getting the input up front. This way, it is possible to get a random position in the string that has not been filled with input yet (e.g. x = 0 and z = 3). The code also contains undefined behaviour (out-of-bounds access).
+ 1
Warnings came out about use of comment markers. There are 2 definition of variable <tah>, a string, and a char array. Both are commented and added yet another warning about undefined variable as I tried to run your code.
Not getting what the lengthy comment below was about unfortunately.
Fixed some of those and got good output (read: no warning nor error).
Just need to confirm what problem you wanted to solve here ...
+ 1
Ipang
so basically,
I have added two definitions of <tah> and <f>,
commented them with a //
making the lines ignored by the compiler,
also, I have coded them with numbers as well like:
/*1*/
/*2*/
/*3*/
etc
the lengthy comments below mean :
example:
Discovery 01:
enabled 3,
it means before running the code, I have removed the '//' from the line that was coded /*3*/
so that the line is no longer a comment and the compiler can read it.
line /*3*/ declares <tah> as a string
Then,
I write the output
In simple words:
initially,
this code cannot be run, without errors
many statements are turned off by turning them into comments
necessary lines can be turned on by removing the '//' from the line
The Discovery logs below show
that
when necessary lines are turned on what the outcome is
in Discovery 1
we drclare <tah> as a char array and run the code
in Discovery 2
we declare <tah> as a string and run the code
in Discovery 3
we introduce <f>
by turning on line 2 and 5 with 3 or 4
and so on
+ 1
Ipang
is it understandable now
or do I need to clarify myself even further?
+ 1
Ipang
It was an old project of mine,
to scramble a word in to a mess
and find the probability of randomly finding that word in the mess
But back then I didn't know much,
So I initially made it with 4 char words
Now I can fulfill my original intention,
no problem with that
But when I was messing around with this old code to have fun
I messed around with the variable declarations and got some interesting results
I noted those results into Discoveries and made a on/off switch system for lines of codes
(by making them comments)
as a result ,
I can mark my discoveries with the information of,
which statements were implemented and which were kept as comment during each discovery
I just want some explanations behind the Discoveries.
+ 1
Ok I guess I'm getting a bit clearer view now.
So which of the discoveries interests you most? I will follow the steps (by uncommenting), follow through by running it and observe outputs.
I'll try to word it out if i could figure out what and why. But if I don't write anything later on, it might just be possible that I got lost as well : )