Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

What Is A Database And How Do I Use It

Authors: Matt Anniss

1st Edition

1622750799, 978-1622750795

More Books

Students also viewed these Databases questions