Alex Aldridge Asa
Alex Aldridge Asa

Reputation: 15

Store char into a char matrix (C programming)

I'm trying to develop a robot simulator. He can move inside a virtual world (100x100 char matrix). I can give him orders like "move right 50 positions", "move left 80 positions", etc.

I've got all this stuff done. The problem is that I want to show the final position of the robot in the screen by storing an "x" char in its final position.

For example, assume that its final position is (50,50), I should store a x char in the world[50][50].

I've tried by doing:

world[50][50]="x";  

But it does not work.

Upvotes: 0

Views: 1758

Answers (4)

aakansha
aakansha

Reputation: 695

Since its a char matrix so use single quotes(' ') instead of double quotes.

world[50][50]='x';

this will solve your problem.

Upvotes: 0

user1684140
user1684140

Reputation: 534

double quotes "x" - is a string, mean that "x" = 'x' + '\0'.

single quotes 'x' - is a single char 'x' = 120 .

Upvotes: 1

Kerrek SB
Kerrek SB

Reputation: 477070

Single quotes:

world[50][50] = 'x'.

Upvotes: 1

vascop
vascop

Reputation: 5212

A char is represented by 'x' in C. "x" is a string. You should use single quotes on the assignment.

Upvotes: 6

Related Questions