The prototype: char* strucstring(struct* info);
throws the following errors:
6, 19 error: declaration of anonymous struct must be a definition
6, 19 error: expected parameter declarator
Change it to ((based on modification of your edit to the typedefed struct, see below):
char* strucstring(info_s *info);
(There are other errors as well. Compile your code with warnings turned on to see all of them.)
Assuming a minimal definition of your struct
:
typedef struct {
char firstname[80];
char lastname[80];
char address[80];
}info_s;
Given your struct definition (with minor modifications from your post's edit.)
typedef struct {
char* firstname;
char* lastname;
char* address;
} info_s;
Each of the members needs to be populated before passing as an argument. This can be done in several ways, simple assignment statements are used below
An example of your code adapted with corrections, including proper way of allocating memory for string: (Credit to @Jabberwocky, +1)
typedef struct {
char *firstname;
char *lastname;
char *address;
}info_s;
char* strucstring(info_s *info);
int main(void)
{
//populate each struct member with content:
info_s info = {"Roger", "Bains", "1234, Noble Rd, Christchurch"};
char *string = strucstring(&info);
printf("%s",string);
free(string);
return 0;
}
char* strucstring(info_s *info)
{
int sizeneeded = 1 + snprintf(NULL, 0, "%s %s %s",info->firstname, info->lastname, info->address);
char * string = malloc(sizeneeded);
sprintf(string, "%s %s %s",info->firstname, info->lastname, info->address );
return string;
}
Note also the cast has been removed from malloc()
for these reasons.