Hi, I'm new to programming.. started a basic evening course and currently working on strutures.
The examples the course gave us are incomplete so I'm not sure why the following code isn't working..
so wondering if someone can check this out.
I think basically I've written the string of arrays (I think that is the correct term) wrong in the address function. When I run it in Visual Studios Express 2008 I get an exception error message pop up rather than a failed message in debug. the code is as follows.. thanks for reading
Full codeCode:void get_address ( struct FRIEND add[], int num ) { int line = 0; for ( line = 0; line < num; line++ ) { printf ( "Enter your friends Address\n:" ); printf ( "Enter line %d of address:", line + 1 ); gets ( &add[num].person.address ); } }
Code:#include <stdlib.h> #include <stdio.h> #include <string.h> struct CONTACT { char name[30]; char address[4][30]; char postcode [8]; }; struct DOB { int day; int month; int year; }; struct FRIEND { struct CONTACT person; struct DOB date_birth; }; void get_mate ( struct FRIEND *mate); void get_address ( struct FRIEND add[], int num ); void get_birth ( struct FRIEND *mate ); void main() { struct FRIEND mate; struct FRIEND add[4]; get_mate ( &mate ); get_address ( add, 4 ); get_birth ( &mate ); } void get_mate ( struct FRIEND *mate) { printf ( "Enter your friends details:" ); printf ( "\nEnter Name: " ); gets ( &mate->person.name ); } void get_address ( struct FRIEND add[], int num ) { int line = 0; for ( line = 0; line < num; line++ ) { printf ( "Enter your friends Address\n:" ); printf ( "Enter line %d of address:", line + 1 ); gets ( &add[num].person.address ); } } void get_birth ( struct FRIEND *mate ) { printf ( "\nEnter Date of Birth:" ); printf ( "Year: " ); scanf ( "%d", &mate->date_birth.year ); fflush ( stdin ); printf ( "Month (1-12): " ); scanf ( "%d", &mate->date_birth.month ); fflush ( stdin ); printf ( "Day: " ); scanf ( "%d", &mate->date_birth.day ); fflush ( stdin ); }