Guardian
Guardian

Reputation: 105

cant get array to print in c

Why wont the array print I'm using c not c++. what am I doing wrong? I would also like to know what characters you can use in a char variable.

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

int main(int argc, char *argv[])
{
   int map[4][4] = {1,1,1,1,1,1,11,1,1,1,1,1,1,1,1}; 
   int x, y;
   for (x = 0; x < 4; x++);
   {  
     for (y = 0; y < 4; y++);
     {    
       printf ("%i ", map[x][y]);
     }
     printf ("\n");
   }   
   return 0;
}

Upvotes: 1

Views: 153

Answers (3)

Iowa15
Iowa15

Reputation: 3079

Get rid of the semicolons on your for loops:

for (x = 0; x < 4; x++)
   {  
     for (y = 0; y < 4; y++)
     {    
       printf ("%i ", map[x][y]);
     }
     printf ("\n");
   }   

Upvotes: 0

hyde
hyde

Reputation: 62777

Snippet from you code:

for (x = 0; x < 4; x++);
  {  
   for (y = 0; y < 4; y++);

Those semicolons at the end of lines. They mean, your for loops do nothing, they are taken as loop bodies.

Upvotes: 4

Salvatore
Salvatore

Reputation: 1185

Get rid of the ';' on both the for lines :)

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


int main(int argc, char *argv[])
 {
 int map[4][4] = {1,1,1,1,1,1,11,1,1,1,1,1,1,1,1}; 
 int x, y;
  for (x = 0; x < 4; x++)
  {  
   for (y = 0; y < 4; y++)
   {    
    printf ("%i ", map[x][y]);
   }
    printf ("\n");
   }   
  system("PAUSE");  
 return 0;
}

Upvotes: 5

Related Questions