answersLogoWhite

0


Best Answer

// to find the length of the string by using array

#include<stdio.h>

#include<string.h>

int main()

{

int i=0,len[21],n;

char str[8][11];

printf("no of name to be enter");

scanf("%d",&n);

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

{

printf("enter the %d string : ",i);

scanf("%s",str[i]);

}

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

{

len[i]=strlen(str[i])-1;

}

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

{

printf("\n lenght of %d string are ",i);

printf("%d",len[i]);

}

return(0);

}

User Avatar

Wiki User

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

Wiki User

15y ago

int strLen(char* str) {

// point current at the beginning of str

char *current = str;

// loop until we get to the null character

while( current[0] != '\0' ) {

++current;

}

return (current - str);

}

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

#include<stdio.h>

main()

{

char str1[100];

gets(str1);

int i=0;

i=len(str1,i);

printf(" \nlength of string is %d",i);

}

int len(char s1[],int i)

{

printf("\n%c",s1[i]);

int sum=0,count =1;

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

return 0;

else

return (count += len(s1,++i));

return count;

}

This answer is:
User Avatar

User Avatar

Wiki User

6y ago

int Strlen (const char* str) { int len = 0;

if (!str) return len;

while (*str++) ++len; // count all characters up to but not including the null-terminator

return len;

}

Note that this function is unsafe; if the string is not null-terminated, the function will attempt to count characters beyond the range of the string until a null character is encountered, yielding a length that may be larger than the buffer's actual capacity. However, any attempt to dereference memory that does not belong to our program will result in undefined behaviour.

To make the function safe, we must pass the maximum length of the buffer. We are then looking for a null-terminator within the range of the buffer's length. If the return value is equal to the buffer's length, then the string has no null-terminator.

int Strnlen (const char* str, int max_length) {

int len=0;

if (!str) return len; while (len<n && *str++) ++len; // count all characters up to but not including the null-terminator

return len;

}

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

int strlen (const char *psz) {

int i = 0;

while (*psz++ != '\0') i++;

return i;

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a C plus plus Program to find the length of the string using pointer?
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.


Write a program to implement the various operations on string such as length of string concatenation reverse of a string copy of a string to another in VB?

what is string


How do you write a algebraic expression for twice as long as the length of the string?

You can write 2X, where X is the length of the string.


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.


How do you display a text reversely in C language without using onlu simply input and output?

#include&lt;stdio.h&gt; #include&lt;conio.h&gt; void main() { char string[20]; int i=0; printf("Enter the string.\n"); while(i&lt;=19) { scanf("%c",&amp;string[i]); i++; } while(i&gt;=0) { printf("%c",string[i]); i--; } getch(); } In this program it is compulsory to enter 20 characters. Now we can write a program in which it is not necessary. #include&lt;stdio.h&gt; #include&lt;conio.h&gt; #include&lt;string.h&gt; void main() { char string[20]; int length; printf("enter the string.\n"); gets(string); length=strlen(string); length--; while(length&gt;0) { printf("%c",string[length]); length--; } getch(); }


How do you write a function called mystrlen that receives a pointer to a character string so that the function return the length of the string?

int mystrlen (const char *s) { const char *t; if (!s) return 0; for (t=s-1;*++t;); return t-s; }


Why pointer is used to reference a string of characters write C plus plus statements that display the text hello using pointer to a string notation?

We use a pointer to reference a string because a string is an array of characters where every element is a char (or a wchar_t if using UNICODE strings). Passing arrays by value would require the entire array to be copied, but passing a pointer variable to an array only copies the pointer, which is effectively the same as passing the array by reference. #include &lt;iostream&gt; int main() { char * psz = "hello"; // pointer to a null-terminated string. std::cout &lt;&lt; psz; // pass the pointer (by value) to the insertion operator. return( 0 ); }


Write a program in java to display a string message using Servlets?

i dont no string for servlate


What is algorithm to write algorithm to the program to access a pointer variable in structure?

Here is the algorithm of the algorithm to write an algorithm to access a pointer in a variable. Algorithmically.name_of_the_structure dot name_of_the _field,eg:mystruct.pointerfield


What is cputs function in computer c plus plus?

Nothing.The C language only recognizes a few keywords, like "for" and "if". Most of what's in a C program ... that doesn't reference routines in the C program itself ... are library calls, and cputs() is one of those. What it does is write its argument (which should be a pointer to a character string) to the console... console put 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))