When I try to compile the following code (GREATLY trimmed down to the necessities) with GCC, I get the warnings below:
typedef struct {
int day, month, year;
} DATE;
typedef struct {
int code;
DATE birth, performance;
float ebird, reg;
double time;
char series, expertise;
char state[2];
char* first, last, title;
} SPKR;
...
...
void getFirstName( SPKR spkr )
{
int max = 512;
int read;
char *temp;
temp = (char*) malloc(max * sizeof(char));
printf("Please enter the first name of the speaker.\n");
printf("First name: ");
read = getline(&temp, &max, stdin);
spkr.first = (char*) malloc((read + 1) * sizeof(char));
strcpy(spkr.first, temp);
}
void getLastName( SPKR spkr )
{
int max = 512;
int read;
char *temp;
temp = (char*) malloc(max * sizeof(char));
printf("Please enter the last name of the speaker.\n");
printf("Last name: ");
read = getline(&temp, &max, stdin);
spkr.last = (char*) malloc((read + 1) * sizeof(char));
strcpy(spkr.last, temp);
}
void getTitle( SPKR spkr )
{
int max = 512;
int read;
char *temp;
temp = (char*) malloc(max * sizeof(char));
printf("Please enter the title of the speech or event.\n");
printf("Title: ");
read = getline(&temp, &max, stdin);
spkr.title = (char*) malloc((read + 1) * sizeof(char));
strcpy(spkr.title, temp);
}
...
...
The warnings I get from GCC are the following:
warning: assignment makes integer from pointer without a cast
warning: passing argument 1 of strcpy makes pointer from integer without a case
This is also the case for a function that fills in the last name, and for the title, but NOT the first name. The odd thing is, when I put my struct like this...
typedef struct {
int code;
DATE birth, performance;
float ebird, reg;
double time;
char series, expertise;
char state[2];
char* first;
char* last;
char* title;
} SPKR;
It works fine and without complaint. Is it a quirk of pointers that makes me unable to list them out like I did at first? Listing them out each on their own line is the only solution I've been able to find (and that through experimentation).
I've technically solved the problem, but the why is going to bother me until I can fix it: I don't want to make a similar mistake in the future.

New Topic/Question
Reply




MultiQuote





|