Thread: arrays of char strings

  1. #1

    Unhappy arrays of char strings

    if i wanted to enter a number of persons names and store them in an array . How would i go about doin this . Do i use two arrays , one for the indididual char and on for the string, or some other way . What condition do i use to see if all the name contain letters of the alphabet.

  2. #2
    Registered User Engineer's Avatar
    Join Date
    Oct 2001
    You would probably want to use a two-dimensional array to store the names like this:

    char names[max_num_of_names_to_store] [ max_name_length];

    To check if the string contains alphabetic chars use: isalpha() from the ctype.h library. ctype.h has several useful functions to verify the input.

    1 rule of the Samurai Code: if you have nothing to say, don't say anything at all!

  3. #3
    Registered User
    Join Date
    Oct 2001
    You could also build a structure.

    struct peoplearray {
    char name[40]; <-- you can choose the size
    } namearray[4000];

    Reference it as namearray[i].name, works great in Visual C++.

    It will also allow you to add addition features to the name, say age, or address, and keep them all together.

    struct peoplearray {
    char name[40]; <-- you can choose the size
    int age;
    char address[40];
    } namearray[4000];


    Hope this helps.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. The Interactive Animation - my first released C program
    By ulillillia in forum A Brief History of
    Replies: 48
    Last Post: 05-10-2007, 02:25 AM
  2. I'm having a problem with data files.
    By OmniMirror in forum C Programming
    Replies: 4
    Last Post: 05-14-2003, 09:40 PM
  3. Structures Arrays and Char Strings
    By Crocksmyworld in forum C Programming
    Replies: 5
    Last Post: 01-19-2002, 11:56 PM
  4. errors in class(urgent )
    By ayesha in forum C++ Programming
    Replies: 1
    Last Post: 11-10-2001, 10:14 PM
  5. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 05:26 PM