Question
Please, please please consider paying attention to the requirements asked in the problem. Please read it thoroughly. My getData function has issues with the error
Please, please please consider paying attention to the requirements asked in the problem. Please read it thoroughly. My getData function has issues with the error code C6262. When I execute the code it does work for the first route but when I enter 'Y' to enter another sentence it just counts my Y as a word and doesn't do anything else. Also I don't know how to At least reference a variable using pointers.
I already posted once and had to ask questions and still, the code doesn't work. Please make sure you are using visual studio 2019 when you are taking this issue. Below is the criteria:
/* * Write a function that accepts a pointer to a C-string as an argument and returns the * number of words contained in the string. Demonstrate the function in a program that asks * a user to input a string then passes it to the function. The number of words in the * string should be displayed on the screen. */ /* Create a function for data input, a function for data processing, and a function for displaying data. (MVC). */ /* The program must be terminated by the user. The program must show a menu with the options of running the program again or terminate. */ //At least reference a variable using pointers.
#include
//prototype functions void getData(); int Word_Counter(char*);
int main() // to display theresults - main function { char again; // To hold Y or N input cout << "***This program will count the number of words yu type.***" << endl; do { getData(); cout << "Do you want to enter another sentence? (Y / N) "; cin >> again; } while (again == 'Y' || again == 'y'); // to terminate or continue
return 0; }
void getData() // function to display the data { cin.sync(); const int STRING_SIZE = 300000; char myString[STRING_SIZE]; int words; cout << " Enter you string: " << endl; cin.getline(myString, STRING_SIZE); words = Word_Counter(myString); cout << " The number of the words are : " << words << endl; }
int Word_Counter(char *myString) // function to count the words { int Counter = 1; while (*myString > 0) { if (*myString == ' ') Counter++; myString++; }
return Counter; }
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