Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6704997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:21:10+00:00 2026-05-26T07:21:10+00:00

I’ve been trying to tweak this problem from my textbook that explains arrays of

  • 0

I’ve been trying to tweak this problem from my textbook that explains arrays of structures.
My output was correct, but when I added another ‘person’ to my structure, and tried to print the result (in the 2nd print statement in displayStats()), it outputs 4 lines instead of 2. Running this code, the output is:

Hoover, Adam: 10.400000 PPG in 2005
, : 0.000000 PPG in 0
.N=ö, Ðè/: 0.000000 PPG in 1
Jane, Mary: 10.400000 PPG in 2005

This is kind of interesting because even when I comment out the second print statement (which prints the Mary Jane line), the output is still 2 lines — Hoover, Adam being line 1, and , : 0.00000 being line 2. When I make all 4 fields in the array [32], I still get 4 lines of output, but the middle 2 lines are changed a bit.

I’m probably missing something really simple, but the goal is just to have 2 lines of output with Hoover, Adam and Jane, Mary.

#include <stdio.h>
#include <string.h>


struct person { /* "person" is name for structure type */
  char first[32]; /* first field of structure is array of char */
  char last[32]; /* second field is array of char */
  int year; /* third field is int */
  double ppg; /* fourth field is double */

  char second[31];
  char third[31];
  int year1;
  double ppo;
}; /* ending ; means end of structure type definition */


displayStats(struct person  Input) {
      printf("%s, %s: %lf PPG in %d\n", Input.last, Input.first, Input.ppg, Input.year);
      printf("%s, %s: %lf PPG in %d\n", Input.third, Input.second, Input.ppo, Input.year1);
   }

 int main(int argc,char *argv[]) {
  struct person  teacher;
  struct person  another;

  teacher.year=2005;
  teacher.ppg=10.4;
  strcpy(teacher.first,"Adam");
  strcpy(teacher.last,"Hoover");
  displayStats(teacher);

  another.year1=2005;
  another.ppo=10.4;
  strcpy(another.second,"Mary");
  strcpy(another.third,"Jane");
  displayStats(another);

  return (0);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:21:11+00:00Added an answer on May 26, 2026 at 7:21 am

    You are seeing garbage because for teacher, second and third aren’t assigned, and for another, first and last aren’t assigned?

    Why do you have second and third fields? Remove them, use first and last for both, and remove the second line in displayStats, and it should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.