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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!