Character weird symbol, scrabble game.

Ok, please come to me with caution cause I'm a beginner and I'm not good in english but uhmm I'm having trouble creating the most important part of my scrabble game project. I'm trying to print a character but it always ends up being a weird symbol. I tried %s but it's giving me an error about STATUS_ACCESS_VIOLATION so i tried %c. I'm also having trouble initialize a char from the char array. I tried grid[i][j] = "a";, but it keeps saying assignment makes integer from pointer without a cast. So I'm temporarily turning into that just to test. I'm just testing this by the way b4 I go on for the real part.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<stdio.h>
#include<string.h>


main(){
	int choice;
	char grid[12][12];
	int i, j;
	for(i=1; i<=12; i++){
		for(j=1; j<=12; j++){
			if (j==1 && i!=1);
				grid[i][j] = (char)i;				
				printf("%c", grid[i][j]);
				
		}
		printf("\n\n");
	}
}
Your code sets incorrect ASCII values into you char grid. The ASCII value for 'a' is 97.
http://www.asciitable.com/
First of all, the values of i and j are not correct in the loop.
The array has 12 elements, the subscript goes from 0 to 11.
11
12
    for (i=0; i<12; i++) {
        for (j=0; j<12; j++) {

The printf with %c looks ok.
But the initial value here is not suitable:
 
grid[i][j] = (char)i; 

You could do something like this:
 
grid[i][j] = i + 'A'; 

Take a look at the ASCII table here:
http://www.asciitable.com/
So you mean I've got to put the value of the letter from the ASCII. What if I just want to put it as string since it's a char array anyway. Even if it's just a single char. %s is not working for me, it keeps saying status access violation.

Can you please give me the exact code.

Oh, and what if I want to print an integer as a char
Last edited on
So you mean I've got to put the value of the letter from the ASCII. What if I just want to put it as string since it's a char array anyway. Even if it's just a single char. %s is not working for me, it keeps saying status access violation.

Can you please give me the exact code.

Oh, and what if I want to print an integer as a char

OOPs. Sorry for double post
Last edited on
I don't know whether this problem has been resolved. I just wanted to clarify a couple of points.

There is a difference between a character and a string. I think there may be some confusion between the two.

"s" is a string, while 'c' is a character - notice the difference between single and double quotes. Likewise, when using the C functions scanf() and printf(), %c means a character and %s means a string.

In more detail, the string "A" is actually an array of two characters, like this,

1
2
3
4
5
    char array[2] = { 'A', 0 };
    printf("array = %s\n", array);
    
    char ch = 'A';
    printf("ch = %c\n", ch);

Last edited on
Topic archived. No new replies allowed.