answersLogoWhite

0


Best Answer

/* with run-time library */

int len;

char* str;

len = strlen (str);

/* without run-time library */

int mystrlen (const char* str) {

int len;

while (*str != '\0') {

len++;

str++;

}

return len;

}

int len;

char* str;

len = mystrlen(str);

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

char* cString = "Hello World!";

int length;

for (length = 0; cString[length]; ++length);

//length now holds the length of cString

else try this out!!!!!!

#include<conio.h>

#include<stdio.h>

void main()

{

char a[20];

int i;

clrscr();

gets(a);

i=0;

while(a[i]!='\0')

i++; //counts no of chars till encountering null char

printf(string length=%d,i);

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

#include<iostream.h>

#include<conio.h>

#include<stdio.h>

void main()

{

clrscr();

int c=1;

int i=0;

int b;

char d[10];

cout<<"Enter the string";

gets(d);

while(d[i]!='\0')

{

b=c++;

i++;

}

cout<<"Length"<<b;

getch();

}

***********************************************

#include<stdio.h>

#include<conio.h>

void main()

{

char a[20];

int i;

clrscr();

printf("Enter the string:");

scanf("%s",a);

for(i=0;i<20;i++)

{

if(a[i]=='\0')

{

printf("string length is:%d",i);

break;

}

}

getch();

}

***************************************************

#include<stdio.h>

#include<conio.h>

void main()

{

char a[20];

int i=0;

clrscr();

printf("Enter the string:");

scanf("%s",a);

while(a[i]!='\0')

{

i++;

}

printf("string length is:%d",i);

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

15y ago

#include <windows.h> #include <stdio.h> void main() { CHAR szTest[32] = {"The Quick Brown Fox"}; size_t thelen = strlen(szTest); printf("The length of the string is %d characters\n",thelen) }

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

Ellipses (...) are used to show indentation for clarity.

int mystrlen(const char *p) {

... int len = 0;

... while (*p++ != '\0') len++;

... return len;

}

or (quicker):

size_t mystrlen(const char *p) {

... const char *q= p-1;

... while ((*++q)!= '\0');

... return q-p;

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

int size(const char *p) { int i; for (i=0; p[i] != '\0'; i++); return i; }

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

int strlen(const char* str) {

int len;

for (len=0; *str++ != '\0'; len++);

return len;

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

size_t mystrlen (const char *s)

{

register const char *t= s-1;

while (*++t);

return t-s;

}

This answer is:
User Avatar

User Avatar

Wiki User

7y ago

size_t Strlen (char* pstr) {

size_t len = 0;

while (*pstr++) len++;

return len;

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a program to find the length of a string?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write a program to find the length of a string in shellscript?

This is an assignment not a question.


How to write A Java program to print number of digits in a given number?

One way to do this is to convert the number to a String, then use the corresponding String method to find out the length of the String.


Write the program in Linux to find the reverse of any string?

i am sam


How do you write a c program to find a word in a string?

what is if(!(str[i]==32))


How do you write a c program to find the smallest word in a string?

what is if(!(str[i]==32))


Do I need to write a program to find a substring in a given string in c plus plus?

No.


Write a c program using string concept enter a sting and replace the new string in to old string and find no of occurrence?

print c co com comp compu


How do you write a program to find the no of words in a given string in dot net?

You find a language that can be targeted towards the .NET Framework. What you are suggesting is something related to string manipulation and you can work with delimiters.


1 Write a program to find the length of a string c plus plus?

#include&lt;iostream&gt; #include&lt;string&gt; int main() { std::string s("The quick brown fox jumps over the lazy dog"); std::cout&lt;&lt;s.c_str()&lt;&lt;std::endl; std::cout&lt;&lt;"The previous string is "&lt;&lt;s.size()&lt;&lt;" characters long."&lt;&lt;std::endl; }


Find length of the string without using loops and control structures?

length = strlen(string);


Program to find the size of the string without using string functions?

You can't. If you want to find the length of a String object, you must use at least one of the String methods. Simply iterate over your char* and count the number of characters you find before you reach the null character . int strLength(const char* str) { int length = 0; // take advantage of the fact that all strings MUST end in a null character while( str[length] != '\0' ) { ++length; } return length; }


Write a program to input a string in the form of name and swap the initials of the namefor example enter a string is rohit Kumar sharma and should be printed RK Sharma?

Get the string from user , then U Split the string with space and put in a string array .Then Find Length of string array , Take first letter of each element in array, Except last. Assigned those to a string, then Fetch Last element of an array, Add it With that String.That's it.