Question
Write a function that accepts apointer to a C-String as an argument and returns the number of words contained in the string.For instance, if the
Write a function that accepts apointer to a C-String as an argument and returns the number of words contained in the string.For instance, if the string argument is "Four score and seven years ago" thefunction should return the number 6. Demonstrate the function in a program thatasks the user to input a string and then passes it to the function. The number of words in the string should be displayed on the screen. Modify the program you wrote for problem 1 word counter so it also displays the average number of letters in each word.
So far i have this for my code, but i cant figure out how to display the average number of letters for each word.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; //Dylan Queary //Also, place your lastnameFirstname on the Project Folder name namespace lastnameFirstname8_2AvgNumOfLetters { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
private void button1_Click(object sender, EventArgs e) { string s = inputTextBox.Text; string[] words = s.Split(' ');
MessageBox.Show("Number Of Words: " + words.Length); }
private void textBox1_TextChanged(object sender, EventArgs e) {
} } }
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