Not Getting Desired Output

This is a discussion on Not Getting Desired Output within the C Programming forums, part of the General Programming Boards category; I'm using first time structures in my program. Problem : I want to make a record of student (maximum 10 ...

  1. #1
    Registered User DevoAjit's Avatar
    Join Date
    Jun 2011
    Location
    Ludhiana, Punjab, India, India
    Posts
    32

    Not Getting Desired Output

    I'm using first time structures in my program.
    Problem: I want to make a record of student (maximum 10 student). so i use arrays structures. After compile and running the program and after entering the data of stuct members, i m getting a error and the program is terminated by windows explorer. somebody help me please.
    Code:
    #include<conio.h>
    #include<stdio.h>
    struct database{
           char name[20][10];
           char clas[5][10];
           int roll_no[10];
           int age[10];
           int marks[10];
           char adress[50][10];
           };
    main()
    {
        int i,totSt;
        struct database student;
        printf("\tStudents's Record\n");
        printf("NOTE: In this program, you can save data for 10 student maximum.\n");
        printf("Number of students:");
        scanf("%d",&totSt);
        for (i=1; i<=totSt; i++)
        {
        printf("Enter Roll Number:");
        scanf("%d",&student.roll_no[i]);
        printf("Enter Name:");
        scanf("%s",&student.name[i]);
        printf("Enter Class:");
        scanf("%s",&student.clas[i]);
        printf("Enter Age:");
        scanf("%d",&student.age[i]);
        printf("Enter Marks:");
        scanf("%d",&student.marks[i]);
        printf("Enter Address:");
        scanf("%s",&student.adress[i]);
    }
        printf("\nRoll No. |    NAME    |  Class   |  Age   | Marks   |     Address");
    for (i=1; i<=totSt; i++)
    {
        printf("\n  %d.    | %s          |  %s      |  %d     | %d    | %s  ",student.roll_no[i],student.name[i],student.clas[i],student.marks[i],student.adress[i]);
        printf("-------------------------------------------------------------------");
    }
     getch();
    
    }

  2. #2
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    Seems like a fence post error in that you start your for loop from one and the ending condition is <= amount. Also it makes much more sense to create a struct that represent 1 student, then make an array of struct student. If you had such a struct you could easily create an array of them like this for an array of 10 student structs:

    Code:
    struct Student student[10];

  3. #3
    Registered User DevoAjit's Avatar
    Join Date
    Jun 2011
    Location
    Ludhiana, Punjab, India, India
    Posts
    32
    Thank you so much. I get the desired results with your help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Not getting the desired o/p with ~ operator. Kindly help.
    By DevinLgls in forum C Programming
    Replies: 5
    Last Post: 05-24-2011, 01:03 PM
  2. Displaying Numbers divisible by user's desired number
    By DaniiChris in forum C Programming
    Replies: 9
    Last Post: 07-07-2008, 03:06 PM
  3. Much desired program.
    By MannyCalavera in forum Projects and Job Recruitment
    Replies: 10
    Last Post: 09-23-2005, 06:40 PM
  4. Replies: 3
    Last Post: 01-08-2004, 09:43 PM
  5. not getting the desired output. WHY???
    By KristTlove in forum C++ Programming
    Replies: 4
    Last Post: 11-06-2003, 02:08 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21