how to copy int from struct

This is a discussion on how to copy int from struct within the C Programming forums, part of the General Programming Boards category; Please help to check with the copy integer part... I have no idea... Thank you! Code: struct studInfo{ char name[256]; ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,497
    > /*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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 01:11 PM
  3. copy struct contents
    By bandal27 in forum C Programming
    Replies: 9
    Last Post: 01-09-2009, 02: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, 12:22 PM
  5. copy struct to class
    By guda in forum C++ Programming
    Replies: 3
    Last Post: 10-06-2003, 09:27 PM

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