小编Ian*_*Twy的帖子

将结构传递给函数

所以我在编译这个程序时遇到了问题,我只是无法让它工作,我的意思是如果我把inputstudent()代码放在里面main(),那就容易了,但我必须将代码放在一个函数中,inputstudent()并从中调用这个main().我知道这听起来很容易,但我无法理解.

#include <stdio.h>
#include <stdlib.h>

struct student
{
    char surname[50];
    int age;
    char oname[50];
    char address[50];
};
void displaystudent();
void inputstudent();

int main(){
    struct student s;
    inputstudent(s);
    displaystudent(s);

    return 0;
}
void inputstudent(struct student s){
    printf("Enter the surname: ");
    scanf("%s",s.surname);
    printf("Enter the other name: ");
    scanf("%s",s.oname);
    printf("Enter the age: ");
    scanf("%d",&s.age);
    printf("Enter the address: ");
    scanf("%s",s.address);    
}
void displaystudent(struct student s)
{
    printf("Surname: %s \n",s.surname);
    printf("Oname: %s \n",s.oname);
    printf("Age: %d \n",s.age);
    printf("Address: …
Run Code Online (Sandbox Code Playgroud)

c structure function

1
推荐指数
2
解决办法
114
查看次数

标签 统计

c ×1

function ×1

structure ×1