for data structures and algorithms in C++ by drozdek in Chapter 1, Problem 5E wh
ID: 3886253 • Letter: F
Question
for data structures and algorithms in C++ by drozdek
in
Chapter 1, Problem 5E
why are you returning a char not an int????
edit - i dont understand why you return a char in this question...:
Please help thanks
Program Code: * This program demonstrates implementation of string functions using pointers #include #include using namespace std I/(a) Strlen function //The function “strienO" finds length of string. It takes /header pointer of character array as function arguments I/checks until the string reaches null and calculates //length of the string. int Strlen(char *s) //Declare a character pointer "tmp" and assign "s" to it char *tmp = s; //Check until null charater reaches while (*s++'o'); //length of the string return s -tmp -1Explanation / Answer
#include <iostream>
#include<conio.h>
using namespace std;
int string_ln(char *);
int string_ln(char*p)
{
int count = 0;
while (*p != '') {
count++;
p++;
}
return count;
}
int main() {
// Declare Variables
char str[20];
int length;
cout << "Calculating the Length of String ";
cout << "Enter Any string [below 20 chars] : ";
cin>>str;
length = string_ln(str);
cout<<" length of the string is: "<<length;
getch();
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.