Thread: Problem with String length

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    8

    Problem with String length

    int main ()

    int strlen(char*s)

    {char *p = s;

    while (*p! = '/0');
    p++;
    return p - s;

    What does this program do?

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    To understand, take a ruler, choose a mark near the left (point A) and the right (point B). If you subtract A from B, you should get the length of segment AB. That's what the program does.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > What does this program do?
    It doesn't do a damn thing, because it won't compile.
    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.

  4. #4
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    yes salem is right.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  3. Replies: 4
    Last Post: 03-03-2006, 02:11 AM
  4. String function problem
    By kzar in forum C Programming
    Replies: 7
    Last Post: 03-27-2005, 05:09 AM
  5. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM