Circuit Negma

C++, C, VB.NET, PCB, Electronics, Circuit Design

alternative to method strlen()

Posted by Circuit Negma on February 6, 2006

#include <stdio.h>

       int i;
       int count;
       char name[50];
       count = 0;
       printf(“please enter your first name: “);
       scanf(“%s”, name);
      for (i = 0; i <=50; i++)     // this is insted of using  strlen();
        {                            // note that in for statment is the condition of termination,
              if (name[i] == ”)   //   thus it can be replaced by the bottom loop.
                count = i;
        for (i = 0; name[i] != ”; i++)  // nothing – do loop is used to write more simply and efficient code.
            count = i + 1;
       printf(“the length of >>> %s <<< is %d\n”, name, count);


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: