Thread: writing in arrays

  1. #1
    Registered User
    Join Date
    Oct 2016
    Posts
    18

    writing in arrays

    here is an excerpt from my homework that I'm having some difficulty with and need some direction.

    "Selecting 2 Prompts the user for a first and last name. Store this information in the system as a student record.
    You should be able to handle 1000 students.
    Student records have
    First name,
    Last name,
    Student ID,
    A list of grades (up to 100 classes). Grades are entered in grade point format (4.0 for an A)
    "

    Basically I have an array where each index is a student and in each index there are the different variables like: first name, last name, ID, and grade. and im having a problem when i have someone input a students first and last name, how would i have it store it inside the first and last name array. This is what i wrote for this part.

    Code:
    else if (a == 2)
        {
        printf("Enter a first name and a last name\n");
                            
        scanf("%s%s",
        }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Examples.

    An array.
    Code:
    char name[100];
    scanf("%s",name);
    An array in a struct.
    Code:
    struct student {
      char name[100];
    };
    struct student s;
    scanf("%s",s.name);
    An array in an array of struct.
    Code:
    struct student {
      char name[100];
    };
    struct students s[20];
    scanf("%s",s[0].name);
    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. Writing a code without arrays!
    By !XOBILE in forum C Programming
    Replies: 14
    Last Post: 01-11-2012, 05:01 PM
  2. Help with writing functions using arrays
    By chrisjg04 in forum C Programming
    Replies: 6
    Last Post: 03-18-2010, 07:59 PM
  3. Reading and writing top arrays
    By qwertysingh in forum C Programming
    Replies: 5
    Last Post: 02-05-2009, 09:56 PM
  4. writing arrays of structures
    By chrismiceli in forum C Programming
    Replies: 6
    Last Post: 06-26-2003, 06:50 PM
  5. writing arrays to files
    By Zaarin in forum C++ Programming
    Replies: 1
    Last Post: 08-30-2001, 11:26 PM

Tags for this Thread