How to detect what is the first character ??

This is a discussion on How to detect what is the first character ?? within the C Programming forums, part of the General Programming Boards category; Code: char *cdx[2]; cdx[1]="/home/dir"; How can i know if the first character is start with "/" or not ?? if ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    41

    How to detect what is the first character ??

    Code:
    	char *cdx[2];
                
                    cdx[1]="/home/dir";
    How can i know if the first character is start with "/" or not ??

    if first char == "/" then
    return 0;
    else
    return 1;

  2. #2
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Basically in a char array of characters it would work like this

    Code:
    char text[5] = "Hello";
    
    if(text[0] == 'H') return 0;
    else return 1;
    but the way your code looks.. I think you could do this

    if(cdx[1][0] == '/')

    if im way of base, post your code so there will be no doubt as to what your trying to do.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    How about isalnum?
    Code:
    if( isalnum( text[0] )
        printf("The first character is either a letter or a number.\n");
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. Character literals incorrectly interpreted
    By DL1 in forum C Programming
    Replies: 11
    Last Post: 04-05-2009, 05:35 PM
  3. Using a character array in a switch question.
    By bajanElf in forum C Programming
    Replies: 10
    Last Post: 11-08-2008, 07:06 AM
  4. <string> to LPCSTR? Also, character encoding: UNICODE vs ?
    By Kurisu33 in forum C++ Programming
    Replies: 7
    Last Post: 10-09-2006, 12:48 AM
  5. Character handling help
    By vandalay in forum C Programming
    Replies: 18
    Last Post: 03-29-2004, 04:32 PM

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