That mean dM has not changed no. But I am not sure about this. If I use %u instead of %p it will give me totally different answers (it says if we use %u it'll convert to decimal. Please give me some advice, and tell me wrong whats with.
Thanks in advance sorry for bother you.
You are not bothering me. It is just hard to help when there isn't much debugging data to help analyze the problems. However, the output you've provided helps. It is also clear from the debugging code you've added and the output you've displayed that you are having problems understanding how pointers work in C. Let me walk you through some of your code and explain what it means.
First, the declarations:
create M, C, and dM as pointers to objects of type uint8_t and the calls to malloc() allocate buffers to hold data to be stored into the areas pointed to by those pointers. Then you have:
The %p in these printf format strings are used to convert the value of a pointer (the address to which the pointer points) to a printable value. But the operands you're providing for these conversions are objects of type uint8_t, not pointers. (C is a pointer, *C is the uint8_t object pointed to by that pointer; M is a pointer, *M is the uint8_t object pointed to by M; dM is a pointer, *dM is the uint8_t object pointed to by dM.) If you want to print the contents of the pointers, the above code needs to be changed to:
If you want to print the unsigned byte pointed to be these pointers (both as an unsigned decimal value and as a printable character), the above code needs to be changed to something like:
Then your code:
is comparing the pointers (not the unsigned 8-bit integers to which they point). Since these pointers were initialized by separate calls to malloc() and not changed since they were initialized, they can't have the same value. They might point to bytes that have the same value, but that would be coded as:
or as:
While we're talking about pointers, you may also see an ampersand followed by an object (i.e., &object). This gives you a pointer to the object. So, for example, the following code segment:
will print the address in memory where ptr is allocated (&ptr), the address in memory of the first byte in the string "abcd" (ptr), and the character pointed to by ptr (*ptr) which in this case is 'a'.
I hope this helps.
This User Gave Thanks to Don Cragun For This Post:
hello all,
I tried a program on an array to intialise array elements from the standard input device.it is an integer array of 5 elements.but after entering the 4th element it throws a message called "Segmentation Fault" and returns to the command prompt without asking for the 5th element.
... (3 Replies)
I have written a program which takes a directory as command line arguments and displays all the dir and files in it.
I don't know why I have a problem with the /etc directory.It displays all the directories and files untill it reaches a sub directory called peers which is in /etc/ppp/peers.the... (4 Replies)
ive written my code in C for implementation of a simple lexical analyser using singly linked list hence am making use of dynamic allocation,but when run in linux it gives a segmentation fault is it cause of the malloc function that ive made use of????any suggestions as to what i could do???
thank... (8 Replies)
Hi,
Why I don't receive a segmentation fault in the following sample.
int main(void)
{
char buff;
sprintf(buff,"Hello world");
printf("%s\n",buff);
}
If I define a buffer of 10 elements and I'm trying to put inside it twelve elements, Should I receive a sigsev... (22 Replies)
I use a binary name (ie polo) it gets some parameter , so for debugging normally i do this :
i wrote script for watchdog my app (polo) and check every second if it's not running then start it , the problem is , if my app , remain in state of segmentation fault for a while (ie 15 ... (6 Replies)
this is a network programming code to run a rock paper scissors in a client and server.
I completed it and it was working without any error. After I added the findWinner function to the server code it starts giving me segmentation fault.
-the segmentation fault is fixed
Current problem -Also... (3 Replies)
Hi Guys,
I just installed and booted a zone called testzone. When I logged in remotely and tried changing to root user I get this error:
"Segmentation fault"
Can someone please help me resolve this?
Thanks alot (2 Replies)
I keep getting this fault on a lot of the codes I write, I'm not exactly sure why so I'd really appreciate it if someone could explain the idea to me.
For example this code
#include <stdio.h>
main()
{
unsigned long a=0;
unsigned long b=0;
int z;
{
printf("Enter two... (2 Replies)
Oddities with gcc, 2.95.3 for the AMIGA and 4.2.1 for MY current OSX 10.14.1...
I am creating a basic calculator for the AMIGA ADE *NIX emulator in C as it does not have one.
Below are two very condensed snippets of which I have added the results inside the each code section.
IMPORTANT!... (11 Replies)