-->

WAP to find length of string without strlen() function.

using turbo c++
----------------------------------------------------------------------------------------------------------------
//wap to find the lenght of given string with out strlen()
#include <stdio.h>
#include<conio.h>
int main()
{
    char string[100];
    int count=0,i;
    printf("enter string\n");
    gets(string);
    for(i=0;string[i]!='\0';i++)
    {
        count++;
    }
    printf("length=%d",count);
    getch();
    return 0;
}






-------------------------------------------------------------------------------
using codeblocks
------------------------------------------------------------------------------------------------------------
//wap to find the lenght of given string
#include <stdio.h>

int main()
{
    char string[100];
    int count=0,i;
    printf("enter string\n");
    gets(string);
    for(i=0;string[i]!='\0';i++)
    {
        count++;
    }
    printf("length=%d",count);

    return 0;
}



or

------------------------------
//wap to find the lenght of given string
#include <stdio.h>

int main()
{
    char string[100];
    int i;
    printf("enter string\n");
    gets(string);
    for(i=0;string[i]!='\0';i++);// loop execution.; no body line; it just takes last value of i.
   
    printf("length=%d",i);

    return 0;
}


No comments:

Post a Comment