• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

C - simple scanf question

onetwenty8k

2[H]4U
Joined
Nov 24, 2006
Messages
2,554
Solved, thank you.

So I am just starting a C course and I just have a quick question. I just need to know why this doesn't work, I want to prompt for both x and y in one scanf line, is this possible in C? I have to adhere to string C89, I just wanted to note.

P.S. This is not an assignment, just a question, I like making code clean.

Code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int main( int argc, char *argv[] )
{
    int x;
    int y;

    printf("Please enter an integer: ");
    fflush(stdout); /* needed becuase output streams are buffered */
    scanf("%d,%d",&x,&y );  /* &x produces the address of x not the value in x */
    printf("x: %d  y: %d\n", x,y );

    return 0;
}

I might as well say, I hate not being able to use // :mad:
 
You messed up with your quotes. The line should read:

scanf ( "%d,%d", &x, &y );
 
You've passed two format strings to scanf(...). It only accepts one.

You can use scanf like this to pick up 2 integers:
Code:
scanf("%d%d", &x, &y);
 
Back
Top