Loading

C Program to Find Length of String Using Command line Argument

C - Program to Find the Length of  String Using Command line Argument


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

void main(int argc,char *argv[])
{
    int len;
    char *ptr;   
    clrscr();
    if ( argc != 2)
    {
        printf("\n Invalid arguments ");
        exit(0);
    }
    else
    {
        ptr=argv[1];
        len=0;
        while ( *(ptr+len) != '\0')
        {
            len++;
        }
        printf("\n Length is %d",len);
    }
}

This entry was posted in . Bookmark the permalink.

Leave a reply