?
Solved

terminate input

Posted on 1998-02-19
3
Medium Priority
?
234 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 200 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.
Suggested Courses

777 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