Avatar of Trevor Maseleme
Trevor Maseleme

asked on 

Using write function to display pointer

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.

[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;
      ft_ft(ptr);
    ft_putnbr(a);
      ft_putchar('\n');
}
/code]
LinuxCUnix OS

Avatar of undefined
Last Comment
evilrix
ASKER CERTIFIED SOLUTION
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Linux
Linux

Linux is a UNIX-like open source operating system with hundreds of distinct distributions, including: Fedora, openSUSE, Ubuntu, Debian, Slackware, Gentoo, CentOS, and Arch Linux. Linux is generally associated with web and database servers, but has become popular in many niche industries and applications.

71K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo