Computer Science, asked by TusharDes, 1 year ago

plz give the code for the question

Attachments:

Aips: Can u rewrite the following question.
TusharDes: sure
TusharDes: write a program in c++ to accept a string and find the length of the string without using library function
Aips: #include<iostream>
#include<stdio.h>

using namespace std;

int main()
{
char a[30];
int i;
cout<<"Enter a string:";
gets(a);

for(i=0;a[i]!='\0';++i);

cout<<"\nLength of the string '"<<a<<"' is "<<i;

return 0;
}
Aips: May this help you
TusharDes: what is the meaning of for(i=0;a[i]!='\0')
Aips: In this case "for(int i = 0; a[i]; i++)", your loop keeps its execution until one of its elements are a null element. Always when you see this expression, it is always the same meaning that is checking out whether element is or not null, in order to stop the loop.
Aips: However that loop has a undefined behavior, because if the index i will arrive at maximum array's size. It's likely you are going to receive a run-time error of that type:

Error for being out of range array size or you are trying to access a null space of memory.

I hope that my answer, it is suitable for your problem..
TusharDes: thank you

Answers

Answered by DxddyExplicit
0
What code? Theres no code for this

TusharDes: c++ program?
Answered by siddhartharao77
1
#include<iostream>

using namespace std;

int main()

{

int user;

char text[25];

cout << "Enter a readable string";

cin.getline(text,25);

while(text[user] != '\0')

{

user++;

}

cout << "\n The length of the string is :" << user;


return 0;

}


Hope this helps!
Attachments:

siddhartharao77: :-))
Similar questions