Thread: strlen

    #1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    421
    Rep Power
    13

    strlen


    I havent found much online how to do this..I just want the user to type out a string and using strlen, give the user how many characters he/she typed..anyone can help real quick? Regards.

    -andy
    hmmm...
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    191
  4. #3
  5. jasondoucette.com
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Canada
    Posts
    378
    Rep Power
    12
    Using strlen() is easy. Just pass it a string, and it returns the number of characters in the string (not including the NULL character at the end). Here's an example from MSDN:

    /* STRLEN.C */

    #include <string.h>
    #include <stdio.h>
    #include <conio.h>
    #include <dos.h>

    void main( void )
    {
    char buffer[61] = "How long am I?";
    int len;
    len = strlen( buffer );
    printf( "'%s' is %d characters long\n", buffer, len );
    }



    Where exactly are you having problems? With the user input, or with using strlen()? There are a number of ways to get user input into a string.
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    421
    Rep Power
    13
    Ahh...thx for the google link..i forgot to put the () at the end of the strlen in my search. I understand now guys, thanks!

    -andy
    hmmm...

IMN logo majestic logo threadwatch logo seochat tools logo