0

I've created a very simple code but it doesn't work! I just want to create an array which will contain strings. However these strings must be put without the character-character method. In other words:

#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
    char wstr[20][10];         
    int i;
    for (i=0;i<20;i++)
            wstr[i]='BA';
    return 0;
}

but the compiler shows me a warning and an error:

[Error] incompatible types when assigning to type 'char[10]' from type 'int'
[Warning] multi-character character constant [-Wmultichar]

What should I do?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
George David King
  • 201
  • 3
  • 4
  • 10

1 Answers1

1
for (i=0;i<20;i++)
            strcpy(wstr[i], "BA");

Single quotes are for single characters; string literals use double quotes. The strcpy() call ensures that you will be able to modify the values later, since modifying the string literal itself is undefined behavior.

Jim Lewis
  • 43,505
  • 7
  • 82
  • 96