2. Code the given function and test it inside the main function. int Length(char* str) { // return the length of string str //write your code here }
2. Code the given function and test it inside the main function. int Length(char* str) { // return the length of string str //write your code here }
C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter9: Completing The Basics
Section9.4: Character Manipulation Functions
Problem 5E
Related questions
Question
2. Code the given function and test it inside the main function.
int Length(char* str)
{
// return the length of string str
//write your code here
}
Expert Solution
Step 1
// Using C program to print the length of the string using pointers
#include<stdio.h>
#include<conio.h>
int Length(char* str){ // function return the length of the string
int length=0; //store the length
while(*str != '\0'){
length++;
str++;
}
return length;
}
int main(){
char str[] = "Helloworld";
printf("%d",Length(str)); //print the length of the string
getch();
}
Step by step
Solved in 2 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning