Thread: Discarding input

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    30

    Discarding input

    Hi

    if I have an input in the form: (character)(number)=(number) i.e a7=5.

    How would you put it in scanf form?

    I've tried:

    Code:
    scanf("a%d=%d", &getchar, &getnum) == 2
    to no avail. To be extra clear I just want to read in the numbers.

    Thanks

  2. #2
    Registered User
    Join Date
    Mar 2011
    Posts
    30
    i've also tried putting "%*c" in front of "%d", but doesn't work for me.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    is (character) always an a? If not, that a in there isn't what you want.
    Code:
    scanf( "%*c"%d=%d\n", &num1, &num2 );
    Read the format specifiers of scanf. Of course when you hit enter, that will get left behind if you aren't reading that too.


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    30
    Genius. thank you

  5. #5
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    hmm...well for a very simple solution what about:
    Code:
    #include <stdio.h>
    
    int main(void){
    
    	int x, y;
    	char c; //again just using this for a simple solution
    
    	scanf("%c%d=%d",&c,&x,&y); //there are other ways.....
    	printf("%d %d", x,y);
    
    	return(0);
    }
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 09-24-2009, 01:28 AM
  2. Help discarding a space in char array
    By cjohnman in forum C Programming
    Replies: 18
    Last Post: 05-13-2008, 09:48 AM
  3. Discarding blank lines?
    By Blurr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 12:30 PM
  4. How can terminate input when input specifed char?
    By Mathsniper in forum C Programming
    Replies: 5
    Last Post: 12-11-2006, 09:59 AM
  5. Help loading a vector with input from input stream
    By Bnchs in forum C++ Programming
    Replies: 9
    Last Post: 11-07-2006, 03:53 PM