Solved

terminate input

Posted on 1998-02-19
3
233 Views
Last Modified: 2010-04-10
How do I alter the getline function to terminate input on any one of few possibilities.

e.g.
~~~~.getline(line,LINEMAX,('\n'||'.'||'\t'||"a '/' followed by a space etc etc))

the above simply doesn't work.

Any help?
0
Comment
Question by:col
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Accepted Solution

by:
q2guo earned 50 total points
ID: 1182533
What you can do is write a new getline function:
Here is what I think it should look like

char *dems should point to array of chars.  Each of the
chars in this array will cause newgetline to terminate.

int newgetline(const ifstream &in, char *buf,  in count, char *dems)
{
      int i=0;
      int k=0;
      char ch;

      while (i <count)
      {
            in.get(&ch);
            buf[i] = ch;
            while (dems[k] != '\0') {
                  if (dems[k] == ch) {
                        buf[i] = '\0';
                        return 1;
                  }
                  k++;
            }
            i++;
      }
      return 0;
}


0
 
LVL 22

Expert Comment

by:nietod
ID: 1182534
that wil work, but you could use strchr() to simplify (and probably speed up) this.

while (i <count)
{
   in.get(&ch);
   if (dems,ch)
   {
      buf[i] = '\0';
      return 1;
   }
   ++i;
   buf[i] = ch;
}

also you realy don't need ch.  I would use the input buffer dirrectly and use a character pointer rather than index buf with [] to speed things up.
0
 

Author Comment

by:col
ID: 1182535
Exactly what I was looking for thanks!!
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question