I created a local structure student c inside the function, how to return student c from function to the the student d in the main fuction?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct student
{
char name[10];
}a,b;
struct student name(struct student *ptr)
{
struct student c;
strcpy(c.name,ptr->name);
return c.name; //error
}
int main()
{
printf("enter name");
scanf("%c",&a.name);
b.name=name (&a.name); //error
printf("%c",b.name);
return 0;
}
int i = 37; return i;? And you call itint j; …; j = intfunc(29);or similar; orint k = 31; int j = intptrfunc(&k);, etc. So, you return a structure the same way:struct student c; …initialization…; return c;. How do you assign the structure in the call:struct student b; …; b = name(&a);(which is also how you pass a pointer to the structure). You don't specify the elements of the structure; you specify the structure variable.