Sajini Biju,
You have several couple choices, depending on what you need to accomplish.
You can pass just the address of the name array:
- void student(char *);
-
void main()
-
{
-
char n[20];
-
scanf("%s",n);
-
strcpy(stud1.name,n);
-
student(stud1.name);
-
}
-
void student(char *k)
-
{
-
printf("%s", k);
-
}
You can pass the entire
stud
structure:
- ...
-
void student(struct stud);
-
void main()
-
{
-
char n[20];
-
scanf("%s",n);
-
strcpy(stud1.name,n);
-
student(stud1);
-
}
-
void student(struct stud k)
-
{
-
printf("%s", k.name);
-
}
You can pass a reference to the
stud
structure:
- ...
-
void student(struct *stud);
-
void main()
-
{
-
char n[20];
-
scanf("%s",n);
-
strcpy(stud1.name,n);
-
student(&stud1);
-
}
-
void student(struct stud *k)
-
{
-
printf("%s", k->name);
-
}
Note, too, that I inserted a format in your
printf()
call. This is to guard against the case where the string to be printed has something that appears as a format specification, which would then result in garbage out.
Luck!