Thanks @grumpy for the detailed explanation.
I used the Boomerang Decompiler for this.
Type: Posts; User: Krabiki
Thanks @grumpy for the detailed explanation.
I used the Boomerang Decompiler for this.
I used a decompiler to decompile a C program and this is the result :
// address: 0x8048504
int main(int argc, char **argv, char **envp) {
char local0[1024]; // m[r28 - 29]
...
Hmm I think setting the struct int variable id to 0 will solve the issue, but I can't figure out how to do it.
Sample code, working code snippet showing the seg fault at the line in which it...
I don't think I did any memory allocation for the pointer =/
The ptr*[1000] actually points to the address of another array which is storing the struct.
Updated the code in the previous post.
Okay I found the source of the segmentation fault.
Hmm how do I properly check if the struct variable id is 0 ?
Non-global int variables are undefined in C from what I found out, so some...
Hmm maybe my phrasing of the sentence is wrong.. When I run the file in GDB, it simply runs without any errors.
What I Did
gcc -ggdb main.c
gdb ./a.out
<run>
will simply run the file with...
GDB doesn't produce any errors as it can be compiled in GCC ..
I try to see if there's any errors lurking somewhere....
I have a c file which can be compiled in Linux via GCC , but when I compile it in NetBeans via Cygwin or MinGW , it doesn't work and keeps throwing a segmentation fault.
Any ideas on how to solve...
How do I store pointers to a struct in an array ?
I am using sprintf to concatenate some values together and then output it to an array in its 1st argument.
A portion of my code is shown...
Oh yeah thanks for the clarification, a moment of confusion there haha :D
p = malloc(...);
q = malloc(...);
p=q;
The final result is that both variables point to the memory block of q.
Why is this so ?
Shouldn't the memory block of q point to p instead ? As q...
vart , thanks for correcting my code logic and the errors :) .
On the other hand, why does a global variable not work ? A global variable is supposed to have the scope of the whole file right ?
Yes, I need to transform it to char because the given printf() function accepts char parameters.
I did some debugging and some inspiration from your code, the issue seems to lie in the conversion....
I am getting multiple function declaration errors when I try to execute the code.
I did a function declaration at the start, is the way I did it wrong ?
#include <stdio.h>
#include...
Oh thanks for the explanation. Didn't thought of operator precedence being the issue =)
Wow rcgldr, thanks for the example, the volatile keyword sounds foreign to me though haha =)
Thanks a lot. Hmm why is the parentheses required in this case ?
Hmm I may be wrong, but aren't continue and break statements "forbidden" in if-else statements ?
It is said that variables in a function cannot be changed by another function. Only by using pointers can variable values be changed.
I am writing some functions to try to prove this theory, but I...
Very clear explanation sonjared ;) , many thanks.
Hmm isn't it the same case when the user enters '1' or '2' ? There shouldn't be any characters in the stream too right ?
Or is it because for '1' and '2' , the presence of scanf causes some...
I am sorry, I don't get the part of "no remaining characters in the stream" =/. Could you explain further ?
Do you mean unifying the input method as in joining the fgets and sscanf in a single...
The following 2 codes are almost identical, only that the switch statements are slightly different.
The 2nd code has the issue of requiring an additional enter key to be pressed when I enter '3'...
After some research, fgets and sscanf is more recommended over scanf.
I tried implementing in my code, but there's an infinite loop without any chance for me to enter any input . Why is this so ?...
Great link, I've read the 2nd part about flushing the buffer. The author raised an important point, what if the user entered more than 1 character, the program will fail. So, flushing the buffer will...