How to get an input from user as an integers array in C? -


this question has answer here:

i'm new c, studying on cs50 course on edx.org (this task not cs50 course).

i wrote program asks user date of birth, , calculates current age depending on system date.

now i'm getting values user way (getint() , getstring() functions cs50.h header , library).

// ask user name, , date of birth  printf("enter name: "); char* name = getstring();  printf("enter day of birth: "); int birth_day = getint();  printf("enter month of birth: "); int birth_month = getint();  printf("enter year of birth: "); int birth_year = getint(); 

but don't want ask user 3 times date can enter 1 line - 18.06.1985 example.

so question - how input user in format dd.mm.yyyy, store in array of integers, [0, 1, 2], able access these values separately later on?

create struct that:

typedef struct {     int day;     int month;     int year; } birthday; 

when you're going ask user, can do:

int day, month, year; printf("type birthday (day month year): "); scanf("%d %d %d", &day, &month, &year); 

now, can set struct properly.

birthday bday; bday.day = day; bday.month = month; bday.year = year; 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -