-4

So for some reason I'm getting messed up values for my c program

I have

int key1[10][3];
int out[4] = {1,0,0,1};
for(i =0;i<10;i++)
{
     for(j=0;j<3;j++)
     {
        key1[i][j] = out[j];
        printf("%d",key1[i][j]);
        //at this point it will print 100
     }
}
    printf("%d",key1[0][0]);
    printf("%d",key1[0][1]);
    printf("%d",key1[0][2]);
// output will be 000

This is driving me nuts am i not declaring my arrays properly in memory or something

*I apologize you guys are right i should have just posted code the solution was some error that was nothing relevant to this please forgive me *

theForgottenCoder
  • 145
  • 1
  • 1
  • 11
  • 2
    int out[1,0,0,1], how is this compiling ? – Eric Fortin Feb 16 '14 at 04:01
  • 1
    It might be helpful to state what your expected output is. – IllusiveBrian Feb 16 '14 at 04:06
  • 2
    I do not believe this code is your real code, it does not exhibit the problem you claim it does. Voting to close until you provide real code to demonstrate the problem. – Crowman Feb 16 '14 at 04:09
  • 2
    Please do not post junk questions like this. The code you post should be the actual code you ran, not something you entered by hand that you *hope* resembles the code that actually failed. – Jim Balter Feb 16 '14 at 04:20

1 Answers1

2

You didn't declare and initialize out array correctly.

Change

int out[1,0,0,1];

to

int out[4] = {1,0,0,1};

Check out How to initialize all members of an array to the same value?.


Update: For your updated question, it will print correct result if you don't forget to declare i, j first.

Check it live: http://ideone.com/Kf5tzC.

Community
  • 1
  • 1
herohuyongtao
  • 49,413
  • 29
  • 133
  • 174