Thread: Char return value

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    42

    Char return value

    I am having y returned instead of the actuall char entered by the user. What am I doing wrong?
    Code:
    #include <stdio.h>
    #include <ctype.h>
    #define SIZE 8 /* Size of board*/
    
    /* function prototype */
    void display(char board[] [SIZE]);
    int valid_moves(char board[] [SIZE], int moves[] [SIZE], char player);
    
    void main()
    {
    	char board [SIZE] [SIZE] ={ 0 }; /* The board*/
    	int moves[SIZE] [SIZE] ={0}; /* valid moves */
    	int row = 0;
    	int col = 0;
    	char queenie = 'Q';	/* user selection*/
    	char y =0;		/* column letter*/
    	int x =0;		/* row number*/
    	char player = 'Q';
    
    	 /* empty all the squares */
    	for(row = 0; row < SIZE; row++)
    	  for(col = 0; col < SIZE; col++)
    	    board[row] [col] = ' ';
    
    	
    
    	display(board);		/* display the board */
    	fflush(stdin);		/*flush the buffer: keyboard--stdin*/
    	printf("please enter the row and column to place the queen:");
    	scanf("%d%c", &x, &y);
    	printf("%x %y\n",x ,y);  /*here is the error it returns y instead of the actuall char entered*/
    	board[x][y]='Q';
    	display(board);	
    	if(x<0 && y<0 || x>SIZE && y>SIZE)
    	{
    		printf(" That is an invalid entry!\n");
    	}
    	/*else &x*/
    }
    
    /* display board funtion definition*/
    void display(char board[] [SIZE])
    {
    	int row = 0;	/* row index */
    	int col = 0;	/* col index */
    	char col_label = 'a';		/* column label */
    
    	printf("\n ");	/*start top line */
    	for(col = 0; col<SIZE; col++)
    	printf("   %c", col_label+col);    /* display the top line*/
    	printf("\n");  	/*end of top line*/
    
    /*display  the intermediate rows*/
     	for(row = 0; row < SIZE; row++)
    	{
    	printf("   +");
    	for(col = 0; col<SIZE; col++)
    	printf("---+");
    	printf("\n%2d|",row + 1);
    
    	for(col = 0; col< SIZE; col++)
    	printf(" %c |", board[row][col]); 	/* display counters in row*/
    	printf("\n");
    	}
    
    	printf("   +");	/*start the bottom line*/
    	for(col = 0; col<SIZE ; col++)
    	printf("---+");	/*display the bottom line*/
    	printf("\n");	/* end bottom line*/
    	}

  2. #2
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    Code:
    scanf("%d%c", &x, &y);
    printf("%x %y\n",x ,y);  /*here is the error it returns y instead of the actuall char entered*/
    Code:
    scanf("%d",&x);
    scanf("%c",&y);   /*if char y;*/
    printf("%d%c",x,y);
    theres no such thing as %y and %x

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    42
    OK. Thanks, I must have been asleep.

  4. #4
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    >>%x is hexadecimal


    thought i saw that somewhere sometime.;but wasnt sure and i didnt had any reference to check it (havent worked with hexadecimals yet ..;:-( )

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  3. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 08:54 PM
  4. String parser
    By sand_man in forum C Programming
    Replies: 13
    Last Post: 08-13-2005, 10:33 AM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 12:54 PM