将信息读入struct数组 [英] Read info into struct array

查看:100
本文介绍了将信息读入struct数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此函数

void insert_book(void)

用于将书信息读入全局数组的第6个元素 book_array ......出错了......当我用这个简单的主要测试来测试它...控制台输出0并且不接受任何输入



我是什么尝试过:



is meant to read book information into the 6th element of global array book_array sth goes wrong..when I test it with this simple main call ...the console outputs 0 and doesn't take any input

What I have tried:

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <string.h>
#include <stdbool.h>
typedef struct
{
    int day;
    int month;
    int year;
} dateStruct;
typedef struct
{
    char title[10];//we need to handle longer titles
    char author[10];//same
    char publisher[10];//same
    char ISBN[10];
    dateStruct date;
    int copies;
    int current;
} book;
book book_array[50];
int i=5;
void insert_book(void)
{
   book inserted;
   gets(inserted.title);
   gets(inserted.author);
   gets(inserted.publisher);
   gets(inserted.ISBN);
   scanf("%d%d",&(inserted.copies),&(inserted.current));
   scanf("%d%d%d",&(inserted.date.day),&(inserted.date.month),&(inserted.date.year));
   book_array[i]=inserted;
   i++;
    return ;
}
int main()
    {
       insert_book;

       printf("%d",book_array[5].date.day);


        return 0;
    }

推荐答案

insert_book;



不是正确的函数调用,它应该是


is not a correct function call, it should be

insert_book();


这篇关于将信息读入struct数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆