2021年1月28日星期四

How to print 2D array in C?

int main() {      int i;    int j;    char mostRecommended[3][50] = {"Star 4", "Time 5", "Wind 3"};      for(i = 0; i < 50; i++) {        for(j = 0; j < 3; j++) {          printf("%s", mostRecommended[i][j]);        }      }    return 0;  }  

I'm trying to print this array to the screen such that it looks like this:

Star 4  Time 5  Wind 3  

I keep getting an error on the declaration line that says "error: expected expression before '{' token" and on the printf line it says "warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]" How do I do this?

Thanks!

https://stackoverflow.com/questions/65947812/how-to-print-2d-array-in-c January 29, 2021 at 10:02AM

没有评论:

发表评论