Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,460 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,107 people online right now. Registration is fast and FREE... Join Now!




Menu driven program

 
Reply to this topicStart new topic

Menu driven program, Counting sentences, characters, lines, and words

colombia23
23 Jan, 2008 - 04:46 PM
Post #1

New D.I.C Head
*

Joined: 20 Jan, 2008
Posts: 3

I don't understand the user option oriented program to count sentences, words, characters, and lines
I don't really know how to start the program and what to write for the cases to get the counting to be done.

CODE

#include <stdio.h>
#include <stdlib.h>

int   getOption (void);

int main (void)
{
    int  Option;
    int curCh;
    int preCh;
    int countLn = 0;
    int countCh = 0;
    int countWd = 0;
    char word = '0';
    int count_sentences = 0;

float count (int option,


void get_text ();
float done = 0;

int option;
float
float
float
float
}
if (! (fp = fopen ("project44.txt", "r")))
{
      printf("Error Opening project44.txt for reading");\
      return (1);
      //if open error
      
      while ((curCh = fgetc (fp)) != EOF);
      {
            switch (option)
       {
       case 1:
            if (curCh != '\n')
            countCh++;
            break;
       case 2:
            if (curCh !=
            break;
       case 3:
            if (word == '0')
            countWd++;
            break;
       case 4:
            
       }//switch
      
       printResult
            

  system("PAUSE");    
  return 0;
}


This post has been edited by colombia23: 23 Jan, 2008 - 04:47 PM
User is offlineProfile CardPM
+Quote Post

MorphiusFaydal
RE: Menu Driven Program
23 Jan, 2008 - 06:16 PM
Post #2

D.I.C Lover
Group Icon

Joined: 12 May, 2005
Posts: 1,212



Thanked: 15 times
Expert In: Hardware, Networking

My Contributions
Please don't double post.

What're you having trouble with? Understanding the problem? Some code error?
User is offlineProfile CardPM
+Quote Post

Nayana
RE: Menu Driven Program
23 Jan, 2008 - 06:42 PM
Post #3

DIC Hawk - 나야나 नयन:
Group Icon

Joined: 14 Nov, 2007
Posts: 824



Thanked: 5 times
Dream Kudos: 175
My Contributions
Well, for a start, your code is never going to do anything.

You need to move your counting code, outside the if block. You're basically saying "if the file can't open, quit the program, then count the word. Otherwise do nothing and quit the program".

Then of course you have more problems with the actual counting code.

You need to start small, then try and finish. You should try one thing at a time...

So why don't you move your counting code outside the if block (to after the if block), then try and write code that will ONLY count the characters.

Then change it so it counts ' ' characters as well.

Then change it so it counts '\n' characters as well.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/7/09 01:52PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month