ok, I need need help with this last program:
Code:
FILE *fp; <- this is just a file with numbers;
<< I'm not providing the entire sourse code, since it's irrelevant
and it's not related to this code>>
int num=0;int num1=0; int num2=0;
int P = 0; int P1 = 0;
int c_1; int c_2; int c_3;
char ch[50];
P = fgetc(fp); P1 = fgetc(fp); // Just getting first 2 characters from a file, I need this for my program
fscanf(fp, "%d%d%d",&num,&num1,&num2); // Since numbers in the file are wrriten in "0 1 2" form
c_1 = num;
c_2 = num1;
c_3 = num2;
char *array2d[c_1][c_2]; // c_1 and c_2 become rows and columns for this array
int row=0; int column=0;
while (fscanf(fp, "%d%d%d",&num,&num1,&num2)==3)
{
sprintf( ch, "%d %d %d", num,num1,num2 );
array2d[column][row] = ch ;
printf("%s",array2d[column][row]); // THIS PRINTS ALL GOOD !
column+=1;
if (column==c_1 && row+1==c_2)
{
break;
}
if (column == c_1)
{
column = 0;
row += 1;
}
}
int start;
int finish;
for (start = 0;start<c_1;start++)
{
for ( finish=0; finish<c_2; finish++)
{
printf("%s", array2d[start][finish]); // WHEN I PRINT HERE, OUTSIDE OF THE WHILE LOOP, IT PRINTS ALL 0s !!!!
}
}
I can't seem to print the 2d array outside the while loop, it just prints all 0s !