1,105,312 Community Members

Printing Structs

Member Avatar
samii1017
Newbie Poster
8 posts since Oct 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Okay, so pretty much I have to use structs to print out information about 4 dogs. However, I can only get the first dog, Smokey's information to print. Any advice on how to get the other four to print?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define pause system("pause")
#define SIZE 100

//Write your structs here
  typedef struct{
      char name[SIZE];
      int age;
      int weight;
      char breed[SIZE];
  } DOG;

//Prototype your functions here
  void displayDog(DOG);
  void loadDog(DOG *s);
  void loadDog2(DOG *s);
  void loadDog3(DOG *s);
  void loadDog4(DOG *s);

main(){
    DOG Smokey, Oscar, Leo, Jose;
    loadDog(&Smokey);
    loadDog(&Oscar);
    loadDog(&Leo);
    loadDog(&Jose);
    displayDog(Smokey);
    displayDog(Oscar);
    displayDog(Leo);
    displayDog(Jose);

    pause;

}//end main


void displayDog(DOG s){
    printf("Student name.....: %s. \n", s.name);
    printf("Age.....: %i. \n", s.age);
    printf("Weight.....: %i. \n", s.weight);
    printf("Breed.....: %s. \n\n", s.breed);
}//end displayDog


void loadDog(DOG *s){
    strcpy(s->name,"Smokey");
    s->age = 5;
    s->weight = 27;
    strcpy(s->breed,"Boston Terrier");
}
//end loadDog

void loadDog2(DOG *s){
    strcpy(s->name,"Oscar");
    s->age = 2;
    s->weight = 70;
    strcpy(s->breed,"German Shepard");
}
//end loadDog

void loadDog3(DOG *s){
    strcpy(s->name,"Leo");
    s->age = 6;
    s->weight = 50;
    strcpy(s->breed,"Siberian Husky");
}
//end loadDog

void loadDog4(DOG *s){
    strcpy(s->name,"Jose");
    s->age = 1;
    s->weight = 60;
    strcpy(s->breed,"Dalmation");
}
//end loadDog
Member Avatar
Moschops
Nearly a Posting Virtuoso
1,363 posts since Sep 2008
Reputation Points: 414 [?]
Q&As Helped to Solve: 266 [?]
Skill Endorsements: 16 [?]
Featured
 
0
 

You are using the same function, loadDog, to put data into all the four dog objects, so you are loading the Smokey data into all four. Perahps you meant to use each loading function once (loadDog, loadDog2, loadDog3, loadDog4).

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article