Thread: output in C

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    12

    output in C

    I've written a program for collecting data of students, it compiles and runs but I've called my show_person function and it is not showing it when I run it?
    Code:
      3 #include<stdio.h>  4 struct Person
      5 {
      6     char name[100];
      7     int age;
      8     float gpa;
      9 
     10 };
     11     void fill_person(struct Person* per)
     12     {
     13       printf("Enter name of student:");
     14       fgets(per->name,100, stdin);
     15       printf("Enter age of student:");
     16       scanf("%d", &per->age);
     17       printf("Enter GPA of student:");
     18       scanf("%f", &per->gpa);
     19 
     20     }
     21     void show_person(struct Person* per)
     22    {
     23       printf("name: %c/n", &per->name);
     24       printf("age: %d/n", &per->age);
     25       printf("GPA: %f/n", &per->gpa);
     26    }
     27 
     28 
     29 
     30 int main()
     31 {
     32 
     33  struct Person per;
     34  fill_person(&per);
     35  show_person(&per);
     36  return 0;
     37 }
    My show_person function is supposed to print out the name, age and gpa of student

  2. #2
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    693
    You do not need the '&' with your printf statements ex) lines 23,24,25. As well as line 23 use %s for strings, %c is just a single character.

  3. #3
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Code:
    void show_person(struct Person* per)
    {
        //printf("name: %c/n", &per->name);
        //printf("age: %d/n", &per->age);
        //printf("GPA: %f/n", &per->gpa);
    
    
        printf("name: %s\nage: %d\nGPA: %f\n", per->name, per->age, per->gpa);
    }
    Fact - Beethoven wrote his first symphony in C

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Also, please just post the code WITHOUT line numbers.
    The board adds line numbers for you.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ overlapping output and adding extensions to output files
    By lordmorgul in forum Linux Programming
    Replies: 9
    Last Post: 05-11-2010, 08:26 AM
  2. How to edit output in struct and call for the output
    By andrewkho in forum C Programming
    Replies: 4
    Last Post: 03-16-2010, 10:28 PM
  3. terminal output not showing output properly
    By stanlvw in forum C Programming
    Replies: 13
    Last Post: 11-19-2007, 10:46 PM
  4. output a string to a standard output
    By sh4k3 in forum C Programming
    Replies: 3
    Last Post: 06-15-2007, 05:59 AM
  5. Replies: 3
    Last Post: 02-19-2003, 08:34 PM