Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- /* Struct basics
- *
- */
- typedef struct {
- char *name;
- double diameter;
- int moons;
- double orbit_time, rotation_time;
- } planet_t;
- void print_array(planet_t *current_planet, char *arr[]) {
- strcpy(current_planet->name, "EARTH");
- strcpy(arr[0], current_planet->name);
- printf("From FUCN %s\n", arr[0]);
- }
- void print_planet(planet_t *p1) {
- printf("%s\n", p1->name);
- printf(" Diameter: %.2f", p1->diameter);
- printf(" Orbit Time: %.2f", p1->orbit_time);
- }
- int main(int argc, char** argv) {
- //planet_t *current_planet = {"", 0, 0, 0, 0};
- char *arr[5];
- char *firstPlanet = "Jupyter";
- planet_t *p1;
- p1->name = malloc(strlen(firstPlanet) + 1);
- printf("HELLO");
- //Assigning values to components
- strcpy(p1->name, "Jupyter");
- strcpy(arr[0], p1->name);
- printf("From string %s\n", arr[0]);
- p1->diameter = 142800;
- p1->moons = 16;
- p1->orbit_time = 11.9;
- p1->rotation_time = 9.925;
- print_planet(p1);
- print_array(p1, arr);
- return (EXIT_SUCCESS);
- }
Advertisement
Add Comment
Please, Sign In to add comment