Thread: Stoping my array

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    7

    Stoping my array

    I have the following:

    char super[30];
    for(nt = 0; nt < 30; nt++)
    cin >> super[nt];

    I am inputting a line such as 24 + 5 - 2 =
    and I want the array to stop letting characters in once someone types the = sign and hits enter. Any ideas? thanks for your help in advance!

  2. #2
    Registered User ski6ski's Avatar
    Join Date
    Aug 2001
    Posts
    133
    I have the following:

    char super[30];
    for(nt = 0; nt < 30; nt++)
    cin >> super[nt];
    Well this is not the right way to do this.
    A better way would be to use:
    Code:
    while(nt!="=")
    {
       //do code here
    }
    C++ Is Powerful
    I use C++
    There fore I am Powerful

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    156
    This will work, but does require the user to hit enter. It reads to = sign and stopes. The cin.ignore is to clear everything from the = to the enter.
    Code:
    #include <string>
    #include <iostream>
    using namespace std;
    
    int main(int argc, char* argv[])
    {
    	char  cLine[81];
    	cin.get( cLine, 80, '=' );
    	cin.ignore( 80, '\n' );
    
    	return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 10:33 AM
  3. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM