Thread: How to input char variables in the same line?

  1. #16
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    United States
    Quote Originally Posted by Lucas525 View Post
    I get what you want to say but when I press "a" the input MUST stop and the program goes to output, in other words, it cannot allow me to input any more letters after "a".
    Ah... then you have to use unbuffered input, which is not provided by the standard libraries. This FAQ will show you several ways to get an unbuffered character. That way the program ends immediately after pressing 'a'.

    Interestingly enough, with what you showed me, concerning something like "pdfjka ifhf" everything after 'a' isn't going to be processed anyway.

    I hope I helped.

  2. #17
    Registered User
    Join Date
    Jan 2012
    It's done! getche() was the command I was looking for. So this is the program:
    #include <iostream>
    #include <conio.h>
    #include <cstring>
    using namespace std;
    int main()
        char suglasnici [43] = {'b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','y','z','B','C','D','F','G','H','J','K','L','M','N','P','Q','R','S','T','V','W','X','Y','Z','\0'};
        char slovo;
        int sam = 0;
        int sug = 0;
        int i;
        cout << "Upisite slova. Za kraj upisite malo slovo a: " << endl;
            slovo = getche();
            cout << " ";
            if (slovo=='a'||slovo=='e'||slovo=='i'||slovo=='o'||slovo=='u'||slovo=='A'||slovo=='E'||slovo=='I'||slovo=='O'||slovo=='U')
                    if(slovo == suglasnici[i])
        cout << "\nBroj samoglasnika je: " << sam << endl;
        cout << "Broj suglasnika je: " << sug << endl;
        return 0;
    The variables and texts are all in croatian. I know I could have made the suglasnici(consonants) variable as a string so it would be shorter but it's ok as long as it's working...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. reading line by line - input function
    By Lindira-123 in forum C Programming
    Replies: 11
    Last Post: 02-06-2011, 03:34 PM
  2. Reading Input from a file, line-by-line
    By Acolyte in forum C Programming
    Replies: 8
    Last Post: 09-30-2007, 01:03 PM
  3. How can terminate input when input specifed char?
    By Mathsniper in forum C Programming
    Replies: 5
    Last Post: 12-11-2006, 09:59 AM
  4. reading a file line by line and char *
    By odysseus.lost in forum C Programming
    Replies: 8
    Last Post: 05-31-2005, 09:47 AM
  5. follow up with char I/O and line, word, and char counting
    By Led Zeppelin in forum C Programming
    Replies: 1
    Last Post: 03-23-2002, 09:26 PM