Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

code check

0 views
Skip to first unread message

Luis Grave

unread,
Dec 29, 1998, 3:00:00 AM12/29/98
to
Asaf,
don't send attachments, paste your in the message body.
see my comments to your code

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
-----------------------------------------------------------

Martin Ambuhl

unread,
Dec 29, 1998, 3:00:00 AM12/29/98
to
Asaf wrote:
>
> Please can some one tell me what is wrong with the following program.
> I cannot access array in a function.

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


Asaf

unread,
Dec 30, 1998, 3:00:00 AM12/30/98
to
----- Sorry friends :-(
#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):");

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;
}

-------

Ben Pfaff

unread,
Dec 30, 1998, 3:00:00 AM12/30/98
to
That program doesn't even compile:

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

Al Bowers

unread,
Jan 1, 1999, 3:00:00 AM1/1/99
to

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


Asaf

unread,
Jan 3, 1999, 3:00:00 AM1/3/99
to
Hi friends
All I wanted was to access an array in a function.

Thanks for all who helped.

Regards, Asaf


0 new messages