Thread: how to copy int from struct

  1. #1
    Registered User
    Join Date
    Mar 2012
    Location
    Hong Kong
    Posts
    13

    Post how to copy int from struct

    Please help to check with the copy integer part... I have no idea...
    Thank you!

    Code:
    struct studInfo{
      char name[256];
      int age;
    };
    
    
    struct studInfo infoArray[1024];
    int studCount = 0;
    
    
    
    
    void addStudent(char* name, int age) {
       if(name == NULL)
          return;
       if(age <= 0)
          return;
     
       strcpy(infoArray[studCount].name, name);
    
       /*Problem Here!, I dont know how to copy integer to struct */
       infoArray[studCount].age = age;              
    }

  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
    > /*Problem Here!, I dont know how to copy integer to struct */
    > infoArray[studCount].age = age;
    Did you try and compile this, because it seems OK here.

    Otherwise, post your ACTUAL error messages.
    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. how can i copy one struct into another?
    By Adam Rinkleff in forum C Programming
    Replies: 20
    Last Post: 07-05-2011, 04:56 PM
  2. How to copy a C struct to a C++ class?
    By Ptbamboo in forum C++ Programming
    Replies: 1
    Last Post: 02-21-2009, 02:11 PM
  3. copy struct contents
    By bandal27 in forum C Programming
    Replies: 9
    Last Post: 01-09-2009, 03:01 PM
  4. How to copy one struct in C to another?
    By cus in forum C Programming
    Replies: 20
    Last Post: 01-03-2009, 01:22 PM
  5. copy struct to class
    By guda in forum C++ Programming
    Replies: 3
    Last Post: 10-06-2003, 09:27 PM