Question
Write a function that returns an integer and accepts a pointer to a C-string as an argument. The function should count the number of characters
Write a function that returns an integer and accepts a pointer to a C-string as an argument. The function should count the number of characters in the string and return that number. Demonstrate the function in a simple program that asks the user to input a string, passes it to the function, and then displays the function's return value.
The following is my code. and it shoud be coded this way except after while. I only need help starting from while.... to the end.
#include
#include
using namespace std;
int functionName(char*);
int main()
{
int size=100;
char line[size];
cout << "Enter string:" << endl;
cin.getline(line, size);
int strCount=functionName(line);
cout << "The number of characters in the string " << " is " << strCount << ". ";
return 0;
}
int functionName(char line[]);
int count = 0;
while (line[count] != '\0')
{
}
return count;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started