Reading few characters from string

This is a discussion on Reading few characters from string within the C Programming forums, part of the General Programming Boards category; Hello all. pls dont shoot me down yet. I'm trying to read the first 5 char from a string array ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    11

    Unhappy Reading few characters from string

    Hello all. pls dont shoot me down yet.
    I'm trying to read the first 5 char from a string array
    example name[20];
    the string is already stored;
    how do i read only the first 5 char say for validation.

    pls help.
    sene

  2. #2
    Green Member Cshot's Avatar
    Join Date
    Jun 2002
    Posts
    892
    they would be stored in:
    name[0]
    name[1]
    name[2]
    name[3]
    name[4]

    This is assuming you meant char array and not string array:
    char name[20];

    Also make sure none of the first 5 are the '\0' character if you're expecting your string length to be 5 or greater.
    Try not.
    Do or do not.
    There is no try.

    - Master Yoda

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    11
    sorry i'm refering to string array.
    hope its not too much bother 'Green yoda'

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>sorry i'm refering to string array.
    In C, the term string normally refers to an array of type char, where the contents is null terminated. What are you refering to?

    >>hope its not too much bother 'Green yoda'
    What other colour would you expect Yoda to be?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    11

    Thumbs up

    thanks master yoda and hammer, i have solved it
    with your help
    hihihi
    cheers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 10:11 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Custom String class gives problem with another prog.
    By I BLcK I in forum C++ Programming
    Replies: 1
    Last Post: 12-18-2006, 03:40 AM
  4. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  5. Another overloading "<<" problem
    By alphaoide in forum C++ Programming
    Replies: 18
    Last Post: 09-30-2003, 11:32 AM

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