Function that accepts a pointer to a string as an argument

Assignment Help C/C++ Programming
Reference no: EM13938448

I'm in dire need of help with coding this function/small program. I have 2 codes that I am working with just need one tha works well. Any help that can be provided would be appreciated greatly.

How it should work:

Write a function that accepts a pointer to a string as an argument and returns the number of words contained in the string.

Must actual count the number of words. User must be able to input a stringand then pass the string to the function. The function must also display the average number of letters in each word.

Codes that I am working with below:
1.)
----------------------------------------------------------------------------------------------------------------
#include "stdafx.h"
#include <iostream>
#include <iostream>
#include <cstring>
#include <ctype.h>

using namespace std;


int main ()
{

const int size = 5;
char WordString[size];

string sentence;


int wordlength = 5;
int wordcount = 0;
int i = 0;

cout<<"Enter a string or sentence: ";
cin.getline( WordString, size );

while( i <= sentence.length() )
{
if( isalpha( sentence[i] ))
{
wordlength++;
}
else if ( wordlength > 0 )
{
wordcount++;
wordlength = 5;
}
i++;

}
cout<<"There are " << wordcount << "words in this sentence."<< endl;
cin.get();

return 0;

}

_______________________________________________________________________
2.)
Tried working with this one also but program doen't allow me to do anything. Exits to early
-----------------------------------------------------------------------------------------------------
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <string>

using namespace std;

int main()
{
char abcd[100]; //string
int wordcnt=0; //word counter!
fflush(stdin);

cout << "\nEnter string: ";
cin.getline(abcd,wordcnt);

if(abcd[0]!=' ') wordcnt++; //account for the first word

for(int i=0; abcd[i]!='\0'; i++)
{
if(abcd[i]==' ')
{
//increment i until non-space char is found
while(abcd[i]==' ')
i++;
//account for spaces at end and increment wordcnt
if(i <= strlen(abcd))wordcnt++;
}
}

cout << "\n\nWord Count: " << wordcnt;
cin.get();

return 0;
}

Reference no: EM13938448

Questions Cloud

How lymphatic system complements function of cardiovascular : Explain the overall function of the entire cardiovascular system including all three components. (Do not, for example, say that the cardiovascular system's function is to circulate blood. That leaves out the function of blood itself.)
Discuss how the innovation component fits : Your task is to visit UBER web site and discuss how the innovation component fits within what has been taught in this course. You will specifically discuss UBER in terms of ethics, security and organizational aspects.
Financial statement-calculate the operating and cash cycles : Consider the following financial statement information for the Ayala Corporation: Item Beginning Ending Inventory $ 10,400 $ 11,400 Accounts receivable 5,400 5,700 Accounts payable 7,600 8,000 Credit sales $ 84,000 Cost of goods sold 64,000 Calculate..
Value and direction of a single resultant force : Determine mathematically the value and direction of a single resultant force which when acting upon the plate shown below would effectively replace the forces shown.
Function that accepts a pointer to a string as an argument : Must actual count the number of words. User must be able to input a stringand then pass the string to the function. The function must also display the average number of letters in each word.
Frank sent invoices to his customers : Frank Crosby (who has never owned or run a business before) started a lawn mowing business (Crosby's Cutters) as a temporary job/business which he intended to run until he started his business degree at the University of Woop Woop in Semester 2, 2..
Two mutually exclusive investment projects for the firm : As a financial analyst for a large firm you are investigating two mutually exclusive investment projects for the firm, project A and project B. After your analysis you find that the IRRA>IRRB, but that the NPVA
Provide the necessary journal entries for kinsella : Kinsella, Inc., has a gross payroll of $8,000 for the pay period. Provide the necessary journal entries for Kinsella to record these payroll taxes.
Determining the effect of process parameters : You are required to write a mini project that is structured in such a way as to answers all the questions contained within the project description.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Construct the arraylisttype class application

Construct the Student Class Student.h and Student.cpp student class should add a Student.h header file for your class definitions and a Student.cpp implementation file comprised of first name, last name, ram id

  Computes the final price for a sales transaction

Create a C program that contains a function that computes the final price for a sales transaction and return that value to a calling method.

  Write a program with a while loop to print 1 to n in square

Write a program with a while loop to print 1 to N in square brackets. N is an integer input from the user. (i) Write the same program using a for-loop

  Program to compute and show miles per gallon

Create the program in C++ which will input miles driven and gallons used (both as integers) for each tankful. Program must compute and show miles per gallon.

  Create valle products accdb database file

Create a new table named Orders using the table design below. You may create your table in design view or datasheet view. Save the Orders table as Orders Your Name. Define a one-to-many relationship between the Customer table and Orders table. Ri..

  Write a method changeblue

Write a method changeBlue(weight). Do not change any color of the pixels in the first half of a picture. For the second half, change blue value of each pixel by new blue=original blue * weight. For example, if a pixel has values (200,100,100) and ..

  Write a small program to simulate a raffle

Write a small program to simulate a raffle (a gambling game) for a group with 100 members. You can simply identify each member with a no-duplicated ID numbers from 01 to 100. A number ticket with a positive 4-digits integer number will be randomly cr..

  Determines and prints the smallest and largest integer

Write a program that accepts 10 integers and determines and prints the smallest and largest integer input by the user.

  Design and implement a library system that does the

design and implement a library system that does the following ? takes details of a studentlibrary users first name last

  Each person in your team will complete one sequence

each person in your team will complete one sequence problem problem 1 or 2. one selection problem problems 3 4 or

  Keep track of the size of the array

Keep track of the size of the array so that you cannot exceed the array boundaries. The implementation details (i.e. the private members)of your class are up to you, but the class should have the following public interface

  Create a bar chart showing the average monthly mean temperat

Write a ++ program to create a bar chart showing the average monthly mean temperature for College Station from 2004 to 2013. The point of the exercise is to compute the sie and location of the rectangles rather than explicitely hardcode that informat..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd