troubleshooting Question

Using write function to display pointer

Avatar of Trevor Maseleme
Trevor Maseleme asked on
Unix OSLinuxC
1 Comment1 Solution813 ViewsLast Modified:
I wrote the attached code with the intention to get 42 as the output but I instead get an asterisks (*) I know that 42 is the ACII value of an asterisk. Please look at my code and see something I might have missed. The program is in C using the <unistd.h> library, I have to use the unistd.h and not the stdio.h for this code.

#include <unistd.h>

void      ft_putchar(char c)
      write(1, &c, 1);

void    ft_putnbr(int nbr)
    write(1, &nbr, 1);

void      ft_ft(int *nbr)
      *nbr = 42;

int      main(void)
      int a;
      int *ptr;
      char c;

      a = 7;
      ptr = &a;
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 1 Comment.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros