lets_go!.c

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

C
58
字号
#include <stdio.h>
#include <string.h>

void main()
{
    struct solarsystem {
        char planet[8];
        double population;
    };

    struct solarsystem planets[9] = {
        "Mercury", 0,
        "Venus", 0,
        "Earth", 5.5E9,
        "Mars", 0,
        "Jupiter", 0,
        "Saturn", 0,
        "Uranus", 0,
        "Neptune", 0,
        "Pluto", 0
        };
    struct solarsystem temp;

    int x;

    puts("Solar System Data");

    for(x=0;x<9;x++)
        printf("Planet %i: %s, Population: %.0f\n",\
            x+1,
            planets[x].planet,
            planets[x].population);

    puts("\nAfter we swap with Jupiter:");

/* Copy Jupiter's data to temp */

    strcpy(temp.planet,planets[4].planet);
    temp.population = planets[4].population;

/* Copy Earth to Jupiter */

    strcpy(planets[4].planet,planets[2].planet);
    planets[4].population = planets[2].population;

/* Copy temp to Earth */

    strcpy(planets[2].planet,temp.planet);
    planets[2].population=temp.population;

    for(x=0;x<9;x++)
        printf("Planet %i: %s, Population: %.0f\n",\
        	x+1,
            planets[x].planet,
            planets[x].population);
}

⌨️ 快捷键说明

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