Thread: Output in C

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    8
    Rep Power
    0

    Output in C


    I've finished an assignment and it compiles and runs but when I run it I'm having some issues with my output. In my show_class function I have it show the name, age, and gpa but when I run it the line with that information looks like this:
    Code:
    Enter name of student:melissa
    Enter age of student:22
    Enter GPA of student:2.22
    name:melissa
    /nage:22/nGPA:2.220000/n
    Here's my code:
    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:%s/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 }
    Anybody know how to fix this?
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,996
    Rep Power
    481
    changing your /n to \n probably will fix the trouble.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    8
    Rep Power
    0
    Thanks !!

IMN logo majestic logo threadwatch logo seochat tools logo