stdb.c

来自「C.Game.Programming.For.Dummies.原码」· C语言 代码 · 共 38 行

C
38
字号
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>

void main()
{
    struct st_info {
        int number;
        char name[30];
        char description[128];
        };
    struct st_info *episode;

    puts("My Star Trek Database");

    episode = (struct st_info*)malloc(sizeof(struct st_info));

    if(episode==NULL)
    {
        puts("No more memory, dude!");
        exit(0);
    }

/* Fill the structure using pointers */

    episode->number = 29;
    strcpy(episode->name,"Operation: Annihilate!");
    strcpy(episode->description,"The one where they beam down to the planet.");

/* Display the data */

    printf("Star Trek Episode %i\n",episode->number);
    printf("\"%s\"\n",episode->name);
    printf("Description: %s\n",episode->description);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?