-
Typedef understanding
in my tutrial a shorthand version for structure like you could do in a program
like ?
Code:
#include <stdio.h>
typedef struct employee char address[50];
int main(void)
{
struct employee emp;
printf("Name is %s",emp.adress);
return 0;
}
thanks in advanced for your help.
-
Yeah, that's a pretty horrible example. Do you have a question about why it doesn't work, or what?
-
More like:
Code:
#include <stdio.h>
typedef struct
{
char address[50];
} employee;
int main(void)
{
employee emp;
/* Initialise emp */
printf("Name is %s", emp.address);
return 0;
}
Of course, the struct could also be named.
-
yes thanks laserswitch i understand it now its just
a shortcut in way to not like struct employee variable you just do
typedef struct employee thenyourshortcut.
-
i tried this code
Code:
#include <stdio.h>
struct employee
{
char name[50];
char address[51];
int age;
float salary;
};
typedef struct employee shortcut;
int main(void)
{
shortcut x;
fputs("Please Enter your age: ",stdout);
scanf("%d",x.age);
printf("Age is %d",x.age);
fputs("Please Enter your salary: ",stdout);
scanf("%f",x.salary);
printf("Age is %f",x.salary);
return 0;
}
but program crashed i dunt know why though.
-
nvm lol i was too fast i forgot refressing it though lol & behind scanf variable
Code:
#include <stdio.h>
struct employee
{
char name[50];
char address[51];
int age;
float salary;
};
typedef struct employee shortcut;
int main(void)
{
shortcut x;
fputs("Please Enter your age: ",stdout);
scanf("%d",&x.age);
printf("Age is %d",x.age);
fputs("Please Enter your salary: ",stdout);
scanf("%f",&x.salary);
printf("Age is %f",x.salary);
return 0;
}
-
Indentation - learn how to do it please!