Problem with String length

This is a discussion on Problem with String length within the C++ Programming forums, part of the General Programming Boards category; int main () int strlen(char*s) {char *p = s; while (*p! = '/0'); p++; return p - s; What does ...

  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
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,627
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,442
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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, 04:45 PM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 10:03 PM
  3. Replies: 4
    Last Post: 03-03-2006, 01:11 AM
  4. String function problem
    By kzar in forum C Programming
    Replies: 7
    Last Post: 03-27-2005, 04:09 AM
  5. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 10:06 PM

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