Once you figure out this character array thing (that must be like page 2 of chapter one), you'll have two choices -- either allocate enough storage with your declarations, or you can go the more exiting route, which is to use a buffer and malloc the space. That gives you the opportunity to learn about functions too:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *assign (char *string) {
char *ptr=malloc(strlen(string)+1);
if (assign==NULL) {
puts("malloc failure!");
exit (-1); // this is really unlikely
}
strcpy(ptr,string);
return ptr;
}
int main()
{
char *firstname, *lastname, *month, *hobbies, *phonenumber, buffer1[4096], buffer2[4096];
int day, year;
printf("First Name and Last Name:\n");
scanf("%s %s", &buffer1, &buffer2);
firstname=assign(buffer1);
lastname=assign(buffer2);
printf("Birth Of Date:\n");
scanf("%s %i %i", &buffer1, &day, &year);
month=assign(buffer1);
printf("Phone Number:\n");
scanf("%s", &buffer1);
phonenumber=assign(buffer1);
printf("Hobbies:\n");
scanf("%s", &buffer1);
hobbies=assign(buffer1);
printf("\n%s %s\n", firstname, lastname);
printf("%s %i %i\n", month, day, year);
printf("%s\n", phonenumber);
printf("%s\n", hobbies);
free(firstname); // remember to free char* that have
free(lastname); // been malloc'd
free(month);
free(hobbies);
free(phonenumber);
return 0;
}
Since you are not using the phone number in any arithmetic, there is really no point in storing it as some form of int. It may seem simpler to just go
Code:
char firstname[20], lastname[20], phonenumber[9], //etc
but you might as well learn about memory allocation as this is a crucial aspect of c programming. The buffers could be ten times smaller, but they are still only 4k of memory, and this way you have basically no chance of an overflow. If you seperate first and last name into two questions, you only need the one buffer.