user inputed struct

This is a discussion on user inputed struct within the C Programming forums, part of the General Programming Boards category; i am writing a function called create_new() that will Cycle through all the fields in the structures and ask the ...

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    34

    user inputed struct

    i am writing a function called create_new() that will Cycle through all the fields in the structures and ask the user to input data for them. If they input invalid data or otherwise abort entry of the data, the function will return a "Not Found" structure.

    Im not sure how to go about this problem. So far, this is what i have.

    Code:
    personal create_new()
    {
    
    }
    Code:
    /* STRUCTURES.h */
    
    typedef enum gender{eUnknown =0, eMale =1, eFemale =2} gender;
    
    typedef struct
    {
     int Birth_month;
     int Birth_day;
     int Birth_year;
    } DOB;
    typedef struct
    {
     char street[25];
     char city[15];
     char state[15];
     char zip[10];
    } address;
    
    typedef struct
    {
     short ID_Number;
     char L_name[25];
     char F_name[25];
     gender gender;
     int salary;
     DOB birth;
     address stuff;
    } personal;
    and...
    Code:
    personal NotFound [1] =
    {
     {0,{"NOT FOUND"},{"NOT FOUND"}},
    };

  2. #2
    Registered User
    Join Date
    Oct 2004
    Posts
    34
    also, i worte the NotFound structure outside of main.... is this wrong or will it not matter?

  3. #3
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Only thing I really see wrong with the NotFound is the [1] part.

    Code:
    personal create_new()
    {
      personal temp;
      printf("ID #: ");
      scanf("%d", &temp.ID_Number);
      printf("Fist Name: ");
      fgets(temp.L_name, sizeof temp.L_name, stdin);
      /* ... */
      printf("Month of birth: ");
      scanf("%d", &temp.birth.Birth_month);
      /* ... */
      return temp;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with linked list sorting function
    By Jaggid1x in forum C Programming
    Replies: 6
    Last Post: 06-02-2009, 03:14 AM
  2. creating a struct based on user input
    By rodrigorules in forum C Programming
    Replies: 1
    Last Post: 09-15-2005, 07:16 PM
  3. Binary Search Tree
    By penance in forum C Programming
    Replies: 4
    Last Post: 08-05-2005, 06:35 PM
  4. Bi-Directional Linked Lists
    By Thantos in forum C Programming
    Replies: 6
    Last Post: 12-11-2003, 10:24 AM
  5. problem with structures and linked list
    By Gkitty in forum C Programming
    Replies: 6
    Last Post: 12-12-2002, 06:40 PM

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