0

my code

#include <stdio.h>

int main()
{
char a[4][4];
a[0] = {65,  , 65,  };
a[1] = {65,  , 65,  };
a[2] = { , 65,  ,  };
a[3] = {65,  ,  , 65};
}

compiler is showing following error :

~/workspace/ $ make task
clang -fsanitize=integer -fsanitize=undefined -ggdb3 -O0 -std=c11 -Wall -
Werror -Wextra -Wno-sign-compare -Wshadow    task.c  -lcrypt -lcs50 -lm -o 
task
task.c:6:12: error: expected expression
a[0] = {65,  , 65,  };
       ^
task.c:7:12: error: expected expression
a[1] = {65,  , 65,  };
       ^
task.c:8:12: error: expected expression
a[2] = { , 65,  ,  };
       ^
task.c:9:12: error: expected expression
a[3] = {65,  ,  , 65};
       ^
4 errors generated.
make: *** [task] Error 1
2

You cannot use = {..} for assigning an array, it's only for initialization. If you want to initialize the array with values, do like:

char a[4][4] = {
    {65,  0, 65,  0},
    {65,  0, 65,  0},
    {0,  65,  0,  0},
    {65,  0,  0, 65}
};

You can assign explicit elements in the array after initializing it

char b[4][4];

b[0][0] = 65;
b[0][1] = ' ';
...
3
  • Have you tried your code ? It's not working.
    – Rahul
    Oct 21 '17 at 11:10
  • What error do you get? The code is working: Live demo
    – tobiaslans
    Oct 22 '17 at 13:01
  • The ASCII code for 'A' is 65, if you want 'a' you would have to print the code for 'a' witch is 97. The live demo of the code prints A, you can always print a char and pass the ascii code you want, like: printf("%c", 65); would print A, or in this case, you could printf("%c", a[0][0]); witch would print A
    – tobiaslans
    Oct 22 '17 at 16:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .