Article View: alt.comp.lang.learn.c-c++
Article #159Re: C++Project1 Text Program
From: Ruel Smith
Date: Wed, 07 Apr 1999 00:00
Date: Wed, 07 Apr 1999 00:00
123 lines
3709 bytes
3709 bytes
How about this:
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
const int kMaxSentenceLength = 50; // maximum length of input
char sentence[kMaxSentenceLength]; // sentence inputed
int count; // loop variable
// get input from the user
/******** whatever prompt you want here ********/
gets(sentence);
// initialize count
count = 0;
// abstract string up to the first parentheses
while(sentence[count] != '(')
{
cout<<sentence[count];
count++;
}
// ignore whatever's in parentheses
while(sentence[count] != ')')
count++;
// get past second parentheses and following space
count += 2;
// abstract the rest of the sentence
while(sentence[count] != '\0')
{
cout<<sentence[count];
count++;
}
// give a carriage return to end sentence
cout<<endl;
return 0;
}
--
Ruel Smith
Cincinnati, OH
Just say no to confusing .ini, .bat, .dll, .exe, and BIOS and buy a Mac!!!
----------
In article <7ee8pe$7uh$1@barcode.tesco.net>, "Victor" <bushmills@tesco.net>
wrote:
> I am trying to devise a program which will read a line of text from the
> prompt which includes one set of brackets round some words, eg the cat (and
> dog) played in the garden. The end result should be that the program should
> output the cat played in the garden therefore omitting the words in
> brackets.
>
> I am at the stage where the program compiles and runs but only displays the
> text before the first bracket. I have tried to get the program to display
> the text after the closing bracket but have been so far unsuccessful.
>
> Has anybody got any suggestions.
>
> I am new to C++ and therefore have only learned some of the simpler
> expressions such as those in the program below.
>
> Many thanks for your time.
>
>
>
> #include <condefs.h>
> #include "Project1io.h"
>
> #pragma hdrstop
>
>
> //--------------------------------------------------------------------------
> -
> USELIB("Project1io.lib");
> //--------------------------------------------------------------------------
> -
> #pragma argsused
> int main(int argc, char **argv)
> {
> AnsiString Sentence;
> int Index;
> Sentence = ReadStringPr("Enter your line of text containing one pair of
> brackets: ");
>
> while (Sentence == "")
> Sentence = ReadStringPr("Enter your line of text containing one pair
> of brackets: ");
> Index = 1;
> while (Sentence[Index] != '(')
>
> {
> WriteChar(Sentence[Index]);
> Index = Index + 1;
>
> }
> while (Sentence[Index] != ')')
>
>
>
> Index = Index + 1;
>
>
>
> getchar();
> return 0;
> }
>
>
Technical Details
Message-ID:
<7egcbj$ff3$1@remarQ.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<7ee8pe$7uh$1@barcode.tesco.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10d4ba,61517f00d25e7060 X-Google-Attributes: gid10d4ba,public X-Google-Thread: 114592,61517f00d25e7060 X-Google-Attributes: gid114592,public X-Google-Thread: 109fba,61517f00d25e7060 X-Google-Attributes: gid109fba,public From: "Ruel Smith" <ruel24@fuse.net> Subject: Re: C++Project1 Text Program Date: 1999/04/07 Message-ID: <7egcbj$ff3$1@remarQ.com> X-Deja-AN: 463749005 Content-Transfer-Encoding: 7bit References: <7ee8pe$7uh$1@barcode.tesco.net> Content-Type: text/plain; charset="US-ASCII" X-Complaints-To: newsabuse@remarQ.com X-Trace: 923514035 9RGZFVYSC7C5BD844C usenet57.supernews.com Organization: Posted via RemarQ, http://www.remarQ.com - Discussions start here! Mime-Version: 1.0 Newsgroups: alt.comp.lang.learn.c-c++,att.lang.c++,comp.lang.c++