Hello~
I do use malloc to allocate array dynamically, which is to assign the number of unit cell(sizeof(unsigned int)) of the memory space corresponding to the element number in a sequence.
And...
Type: Posts; User: HolmesChang
Hello~
I do use malloc to allocate array dynamically, which is to assign the number of unit cell(sizeof(unsigned int)) of the memory space corresponding to the element number in a sequence.
And...
Is it incorrect even if I let user input non-zero n with a following scanf in while()?
So I shouldn't semi-dynamically assign the size of LoS[n] with an initialized 0 then change it afterward?
...
Sorry for the bothering.
I did the function desired.
#include <stdio.h>
#include <memory.h>
Excuse me.
Besides the "segmentation fault" error, I have another different question.
I dynamically assign the number of interested sequence of fixed 4 elements in this code.
If I want to...
Hello
I did a on-line judge problem and the error msg is "segmentation fault"
But the code goes well in my NB, using DEV-C++ 4.9.9.2.
Could somebody give me some hints?
Thanks a lot!
I think it's the point to which I didn't know before.
Now I know it.
Thank you so much.
Thank you.
I read the usage of fflush from a sample code of a textbook.
It talks about how to escape from reading the unwanted \n after getchar();
It also use a following getchar() to "absorb"...
I have tried %p and compared the output with that using %d.
With %p, address in hex format is returned while decimal format with %d.
However, it can't match the output using %p as I tried to...
I think I might figure out why it still output unexpectedly.
After calling scanf, I input y and pressed enter which is recognized as a character.
scanf in the first loop read y and leave \n in the...
Thanks for your hint.
I think I realize the cause of the problem.
pc++ equals to pc = pc+1, changing the memory address of pc.
Its a very basic mistake and I neglect it
You pointed it out...
Hello
I checked the output again and found that the memory address pointed to had been changed without expectation.
I checked by the following code.
#include <stdio.h>
#include...
Thank you!
I found this mistake and corrected it but still with some problems.
Thanks!
I changed the request size of memory in line 26, n=n+3.
realloc allocates new memory space. Is it necessary to request a different size?
I am not sure about what you mean change pc. Do you mean change the value, the type or the memory it points to?
I did change the value of pc after declaring and initiating NULL. I didn't change its...
I am now entering the part of memory management.
As learning from some resources, realloc copies the content pointed by a declared pointer, frees its memory and then allocates a new memory space...
Thank you so much!
Thanks a lot!
Another problem raised is while loop breaks in the 2nd run as I use %c in replace of %s.
I can input the value of char variable using scanf with %c outside loop block without any...
Hello, I am a new learner of C.
I ran into a problem while using while loop.
The declared and initiated local int variable works well with its specified value while running through the 1st run...