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

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

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