qfedu-cpp-level/day1/homework/h4.cpp

45 lines
920 B
C++

#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;
typedef struct file_node_s
{
char filename[32];
int filesize;
file_node_s *next;
} FileNode;
int main()
{
FileNode *head = NULL;
FileNode *fn1 = (FileNode *)malloc(sizeof(FileNode));
strcpy(fn1->filename, "数学");
fn1->filesize = 1000;
FileNode *fn2 = (FileNode *)malloc(sizeof(FileNode));
strcpy(fn2->filename, "语文");
fn2->filesize = 1200;
FileNode *fn3 = (FileNode *)malloc(sizeof(FileNode));
strcpy(fn3->filename, "英语");
fn3->filesize = 1150;
head = fn1;
fn1->next = fn3;
fn3->next = fn2;
fn2->next = NULL;
FileNode *p = head;
while (p != NULL)
{
cout << "文件名: " << p->filename << ", 文件大小: " << p->filesize << endl;
p = p->next;
}
free(fn1);
free(fn2);
free(fn3);
free(head);
return 0;
}