|
-
November 25th, 2004, 12:42 AM
#1
Error In This Code ?????????
Consider the following code
typedef union
{
struct /* Use this for the first array element*/
{
char title[20];
int count;
} header;
struct /* Use this for remaining array elements */
{
double x;
double y;
double z;
} data;
} Coord;
/* This function will allocate an array of n+1 elements. The first element will
/* the title and number of points (n) while the remaining n elements will be
/* individual coordinates.
*/
Coord *allocCoordArray(int n)
{
Coord *retval;
int i=0;
retval = malloc((n+1) * sizeof(Coord));
if (NULL = = retval)
return NULL;
strcpy (retval[i].header.title, “unknown” ) ;;
retval[0].header.count = n;
for (i = 1; i < n+1; i++)
{
retval[i].data.x = 0.0;
retval[i].data.y = 0.0;
retval[i].data.z = 0.0;
}
free(retval);
return retval;
}
Indicate with reasons any problems you see with the code.
Regards,
Amitava
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|