我看过其他几个类似的问题但是没有一个能用我的代码,我放弃了尝试查看的东西.
我正在尝试创建一个程序,将每个具有书名的行从文件转换为字符数组,因为我需要稍后调用每本书,所以书[1],书[2]等等. ,我无法弄清楚如何使用我的结构创建数组.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#define Num_Book 9
typedef struct book {
char *book_name;
size_t length;
ssize_t title;
}BOOK;
int main(int argc, char* argv[])
{
BOOK *Book;
Book = (BOOK *) malloc (sizeof(BOOK));
(*Book).book_name = NULL;
(*Book).length = 0;
char title_arr[Num_Book][50];
//this is the array that I tried creating,
//but it kept giving me warnings when I tried to compile
//opening my file
FILE *f_books;
f_books = fopen("books.txt", "r");
if (f_books == NULL)
{ …Run Code Online (Sandbox Code Playgroud)