Hey Folks,
I'm getting an "incompatible types in assignment" error and warning as well as a "return makes pointer from integer without cast" warning. Yes, I'm a newb. I've been reading the tutorials here and on other sites as well as K & R but I still haven't been able to get this code straigtened out. I want to return the contents of the pointer to char array from each call to get_input to the specified part of the structure in input (). Thanks for reading.
Code:
contact input ();
char* get_input (char[26], int);
Code:
contact input () /* gets an entry from the user */
{
contact entry = {'\0','\0','\0','\0','\0','\0','\0','\0'}; /* initializes the structure */
char prompt1[26] = "Please enter a new name.";
char prompt2[26] = "Enter a street address.";
char prompt3[26] = "Enter a city.";
char prompt4[26] = "Enter a province.";
char prompt5[26] = "Enter a post code.";
char prompt6[26] = "Enter a country.";
char prompt7[26] = "Enter a date of birth.";
char prompt8[26] = "Enter a phone number.";
char prompt9[26] = "Enter an email address.";
entry.name = get_input (prompt1, 50);
entry.add.street = get_input (prompt2, 50);
entry.add.city = get_input (prompt3, 50);
entry.add.state = get_input (prompt4, 50);
entry.add.post = get_input (prompt5, 50);
entry.add.country = get_input (prompt6, 50);
entry.birth = get_input (prompt7, 50);
entry.phone = get_input (prompt8, 50);
entry.email = get_input (prompt9, 50);
return (entry);
}
char *get_input (char prompt[26], int size)
{
char string [50];
char *pointer;
pointer = &string;
char junk = 0;
int length;
do{
printf ("\n%s\n\n>", prompt);
fgets(string, sizeof(string), stdin);
if ( strchr(string, '\n') == NULL ){ /* if overflow */
printf ("\nYour entry is too long, please try again.\a");
while((junk = getchar()) != '\n' && junk != EOF);
string[0] = '\0';
}
} while (string[0] == '\0' || string[0] == '\n');
length = strlen (string);
if (string[length - 1] == '\n'){
string[length - 1] == '\0';} /* replace \n */
return *pointer;
}