Thread: Problem with isalpha

  1. #1
    Registered User
    Join Date
    Jul 2005

    Problem with isalpha

    I have a doubt about the isalpha function
    The literature says that it accepts a variable of type char.
    But I sent a pointer to a char
    This is what I did
          printf("The string starts with a letter\n");
          printf("The first letter is %c\n",*(argv+(temp_counter));
    It seems to compile and run fine on my comp. I am ussing gcc to compile it. But when I sent it to a friend it did not compile on his comp.
    Any idea why this might be happening.
    Thanks in advance.

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    New York
    argv is of type char**. You gotta dereference it twice.

    		if(isalpha(*(*argv + temp_counter)))
    			printf("%c", *(*argv + temp_counter));
    First dereferencing in inner-most parentheses takes argv[0] (path to your program) which is a char*, and then you dereference that again at the position of the temp_counter.
    Last edited by Tonto; 09-25-2005 at 11:03 PM.

  3. #3
    Registered User
    Join Date
    Jul 2005
    opps I am very sorry about that.I made a mistake when copying. This is what I used
    So I have used a pointer to a pointer which points to the first char in the string.
    Using the above an error still occurs.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    You could stop with the pointer arithmetic and just go with the subscript equivalent to make it more obvious which way you're going.

    // first character of every argument
    if ( isalpha ( argv[temp_counter][0] ) )
    // all characters of argument 0
    if ( isalpha ( argv[0][temp_counter] ) )
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Palindrome, problem with isalpha
    By Kyeong in forum C Programming
    Replies: 2
    Last Post: 11-07-2008, 12:28 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
Website Security Test