Passing a struct variable as parameter to a function.

#include <stdio.h>

typedef struct student
{
int rollno;
char name[20];
float percent;
}Student;

void getStudent(Student *); /* Pass by Reference */
void showStudent(Student); /* Pass by Value */

int main(void)
{
Student s;

printf( "\nEnter student info : " );
getStudent(&s); /* Pass by Reference */

printf( "\nDisplaying student info : " );
showStudent(s); /* Pass by Value */

return 0;
}
void getStudent(Student *sp)
{
float f;
if( 0 ) scanf( "%f", &f );

printf( "Enter Roll no : " );
scanf( "%d", &(sp -> rollno));

printf( "Name : " );
fflush(stdin);
gets( sp -> name );

printf( "\nPercentage : " );
scanf( "%f", &(sp -> percent) );
}
void showStudent(Student s)
{
printf( "\nRoll No\t\t: %d", s.rollno );
printf( "\nName\t\t: %s", s.name );
printf( "\nPercentage\t: %f", s.percent);
}

No comments:

Post a Comment

kiss on google ads if you are anonymous because your ip is trackable.thank you.

......from.admin