Finding a string length by a user-defined function(instead of strlen())
If this program make any errors please let me know,i will try to help you out.
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
int mystrlength(char [],int);
main()
{int arraysize=5;
char arr[arraysize];
cout<<"enter the string:";
gets(arr);
int l,x;
l=strlen(arr);
cout<<"The string length by built-in fuction is:"<<l<<endl;
x=mystrlength(arr,arraysize);
cout<<"the string length by my function is:"<<x;
getch();
}
int mystrlength(char arr[],int arraysize)
{
int count=0;
while(arr[count]='\0')
{
count++;
}
return count;
}
If this program make any errors please let me know,i will try to help you out.
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
int mystrlength(char [],int);
main()
{int arraysize=5;
char arr[arraysize];
cout<<"enter the string:";
gets(arr);
int l,x;
l=strlen(arr);
cout<<"The string length by built-in fuction is:"<<l<<endl;
x=mystrlength(arr,arraysize);
cout<<"the string length by my function is:"<<x;
getch();
}
int mystrlength(char arr[],int arraysize)
{
int count=0;
while(arr[count]='\0')
{
count++;
}
return count;
}
No comments:
Post a Comment