How to assign values in C

Status
Not open for further replies.

Mohan Giri

In Runtime
Messages
144
How to assign values to dynamically created multi dimensional array??

For understanding I am posting my code. In my code tell me how to assign values to array.

#include<stdio.h>
#include<conio.h>
main()
{
int *a;
int i,j,k;
int l,m,n;
//clrscr();
printf("Enter i,j,k value to create multidimensional array:");
scanf("%d %d %d",&i,&j,&k);
printf("I=%d J=%d K=%d",i,j,k);
a=(int *)malloc(i*j*k*sizeof(int));
for(l=0;l<i;l++)
{
for(m=0;m<j;m++)
{
for(n=0;n<k;n++)
{
printf("Enter array elements:");
a[n][m][k])=getche(); /* Error at this line: Invalid indirection */

}
}
}
for(l=0;l<i;l++)
{
printf("\n");
for(m=0;m<j;m++)
{
for(n=0;n<k;n++)
{
printf("%d",a[n,m,k]); /* Error at this line: Invalid indirection */

}
}
}

getch();


}
 
i'm sorry, but I've answered many of your basic questions before, and I really feel that you are just using me/us to complete homework assignments that you don't want to put the effort into completeing.

Here's some tips at how to fix this.

1. Debug your code, I see some formatting errors like a ) where it doesn't belong.

2. Take the book that came with your class and read over the section regarding your questions. If you didn't buy the book, google for the specific topic (In this case, dynamic array allocation and assignment).

3. If you're still stuck and all of the above you've done, then post here.
 
Exactly what I said before. I'm not the only one who thinks these questions are your homework questions.
 
Status
Not open for further replies.
Back
Top Bottom