what's wrong here?
typedef struct person
{
int age;
char name[50];
};
int main()
{
struct person test;
test.age = 20;
test.name = "Test";
return 0;
}
what's wrong here?
typedef struct person
{
int age;
char name[50];
};
int main()
{
struct person test;
test.age = 20;
test.name = "Test";
return 0;
}
anyways i fixed it myself :) here is the solution
typedef struct
{
int age;
char *name[50];
} Person;
Person newperson(char *name, int age)
{
Person temp;
*temp.name = name;
temp.age = age;
return temp;
}
int main()
{
Person list[50], ttt;
list[0] = newperson("Test", 20);
*ttt.name = "ASDF";
return 0;
}
Use strcpy to copy a string. You've got more going wrong in that code, though. I think you're after something that might look a bit like this:
#include <string.h>
typedef struct
{
int age;
char name[50];
} Person;
Person newperson(char *name, int age)
{
Person temp;
strcpy(temp.name, name);
temp.age = age;
return temp;
}
thanks for the remark. that was the thing i was trying to remember.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.