arrays of char strings

This is a discussion on arrays of char strings within the C Programming forums, part of the General Programming Boards category; if i wanted to enter a number of persons names and store them in an array . How would i ...

  1. #1
    Unregistered
    Guest

    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
    Posts
    125
    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.

    Cheers.
    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
    Posts
    3
    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];

    namearray[i].address.

    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 Cprogramming.com
    Replies: 48
    Last Post: 05-10-2007, 03:25 AM
  2. I'm having a problem with data files.
    By OmniMirror in forum C Programming
    Replies: 4
    Last Post: 05-14-2003, 10: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

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