Trying to learn how to use structs, i want the user to enter the phone number and the program to print that number back.
main.c
Code:
#include "phone.h"
#include <stdio.h>
int main()
{
phone d;
printf("Enter your phone number: ");
input_phone(&d);
print_phone(d);
return 0;
phone.h
Code:
#ifndef _PhoneH_
#define _PhoneH_
typedef struct {
int areacode;
int actualnumber;
} phone;
void input_phone(phone *dp);
void print_phone(phone d);
#endif
phone.c
Code:
#include "phone.h"
#include <stdio.h>
void input_phone(phone *dp)
{
phone phonein;
scanf("%d-%d",&phonein.areacode,&phonein.actualnumber);
}
void print_phone(phone d)
{
phone phonein;
printf("Your phone numer is %d-%d", phonein.areacode, phoneinactualnumber);
}
If i do a print within input_phone of either areacode or actualnumber it works fine, but the print inside print_phone just displays a ramdon number[FONT=Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace][/FONT]