Asaf wrote:
>
> Please can some one tell me what is wrong with the following program.
> I cannot access array in a function.
>
> Thanx, I`m using Borland C.
>
> Asaf Ayoub
>
#include<stdio.h>
/* Enter fixed loads */
char response;
int FixedLoad[10]= { 200, 350, 375,423, 194, 200, 240, 280, 205 };
int set=0, position=0;
int LoadSet[5][10];
int maxpos=10;
/* Enter the number os sets */
int GetMaxSets()
{
int maxset;
/* get valid number of sets 0-5 */
do
{
printf("\nEnter number of sets (max=5):");
/*############ insert here "fflush(stdout);"
############## to ensure you see the output */
scanf("%i", &maxset);
/*########### read the C FAQ http://www.eskimo.com/~scs/C-faq/top.html
############# to see why scanf is not a good function to do input */
if(maxset <0 || maxset>5)
{
printf("\nError: Enter max sets 0-5: ");
}
fflush(stdin);
/*########## undefined behavior
############ fflush() is only defined to output streams*/
}while (maxset<0 || maxset >5);
return maxset;
}
/* Get data for every set */
void EnterData(int LoadSet[][])
/*########## change to "void EnterData(int LoadSet[][10])" */
{
LoadSet[0][0]=4;
}
int main(void)
{
int maxset;
/* Display title */
printf(" Loading structures\n");
printf(" ==================\n\n\n");
/* Enter the number os sets */
maxset=GetMaxSets();
maxset=0;
/* Enter the data in array */
EnterData(LoadSet[][]);
/*########## change to "EnterData(LoadSet);" */
return 0;
}
--
-----------------------------------------------------------
Luis Grave mailto:lgr...@ccg.uc.pt
Dept. Teletrabalho, Visualisacao and Tecnologias Multimedia
Centro de Computacao Grafica http://www.ccg.uc.pt
-----------------------------------------------------------
The main thing wrong with it is that it is an attached base64-encoded
file. Post your code as text in the body of your message.
--
Martin Ambuhl (mam...@earthlink.net)
Note: mam...@tiac.net will soon be inactive
/* Enter fixed loads */
char response;
int FixedLoad[10]= { 200, 350, 375,423, 194, 200, 240, 280, 205 };
int set=0, position=0;
int LoadSet[5][10];
int maxpos=10;
/* Enter the number os sets */
int GetMaxSets()
{
int maxset;
/* get valid number of sets 0-5 */
do
{
printf("\nEnter number of sets (max=5):");
scanf("%i", &maxset);
if(maxset <0 || maxset>5)
{
printf("\nError: Enter max sets 0-5: ");
}
fflush(stdin);
}while (maxset<0 || maxset >5);
return maxset;
}
/* Get data for every set */
void EnterData(int LoadSet[][])
{
LoadSet[0][0]=4;
}
int main(void)
{
int maxset;
/* Display title */
printf(" Loading structures\n");
printf(" ==================\n\n\n");
/* Enter the number os sets */
maxset=GetMaxSets();
maxset=0;
/* Enter the data in array */
EnterData(LoadSet[][]);
return 0;
}
-------
blp:~(1)$ gcc -Wall -ansi -pedantic foo.c
foo.c: In function `EnterData':
foo.c:35: arithmetic on pointer to an incomplete type
foo.c: In function `main':
foo.c:52: parse error before `]'
You will need to declare the size of the array in the function header;
i.e. LoadSet[5][10]. You also should call the function as
EnterData(LoadSet); leave out the [][], which isn't even valid anyway.
--
"In My Egotistical Opinion, most people's C programs should be indented six
feet downward and covered with dirt." -- Blair P. Houghton
Please: do not email me copies of your posts to comp.lang.c
do not ask me C questions via email; post them instead
Asaf wrote:
....... code snipped .........
> fflush(stdin);
fflush() stdin argument is not defined in Standard C.Read the faq.
It is impossible to determine what you are attempting
with the code you presented. But to make a guess,
if you are attempting to copy an array into an
array of the array you can try it this way.
#include<stdio.h>
#include<string.h>
typedef int arr10[10];
void EnterData(arr10 *dest,arr10 *source);
int main(void) {
arr10 FixedLoad = { 200, 350, 375,423, 194, 200, 240, 280, 205 };
arr10 LoadSet[5] = {0};
int i;
EnterData(&LoadSet[4],&FixedLoad);
for(i = 0; i < 10;i++)
printf("LoadSet[4][i] = %d\n",LoadSet[4][i]);
return 0;
}
void EnterData(arr10 *dest,arr10 *source)
{
memcpy(dest,source,sizeof(arr10));
}
--
Al Bowers
Tampa, FL
mailto:abo...@combase.com
http:www.gate.net/~abowers/index.html
Thanks for all who helped.
Regards, Asaf