EverCrest Message Forums
You are not logged in. Login or Register.
Author
Topic: One FINAL Question
Lechium
With no one to ever know
posted 11-29-2005 08:29:39 PM
I really appreciate the help you guys have been giving me, but I just have one more quick question. I have to Write a C program that uses at least an additional function called by main to calculate and print the sum and difference of corresponding elements of two integer arrays with 5 elements each.

So far I have:

code:
 #include <stdio.h>
void printArray (const int a[][5]);
void main (void)
{
int array1[][5]={15, 13, 80, 5, 16};
int array2[][5]={10, 9, 100, 6, 15};
int Sum_Array, Diff_Array;

printf ("Values in array1 are:\n");
printArray(array1);

printf ("Values in array2 are:\n");
printArray(array2);

}

void printArray (const int a[][5])
{
int i;
int j;

for (i=0; i<=1; i++){
for (j=0; j<=2; j++){
printf ("%d ", a[i][j]);
}

printf ("\n");
}
}


In my first array, I keep getting -4195236, and a couple of other weird, large negative numbers. I have no idea why, I follwed the example that was given in class. Any suggestions?

"The MP checkpoint is not an Imperial Stormtrooper roadblock, so I should not tell them "You don't need to see my identification, these are not the droids you are looking for."
Alidane
Urinary Tract Infection
posted 11-29-2005 08:47:44 PM
Large, strange numbers are generally indicative of dangerous, random memory access. In this case, you've got two two-dimensional arrays of one row each--I think you want one array with two rows and 5 columns, or two one-dimensional arrays.

If you're going to be taking any more programming classes, I suggest learning how to use gdb--it's very, very helpful.

Alidane fucked around with this message on 11-29-2005 at 08:48 PM.

Burger
BANNED!
posted 11-30-2005 12:08:36 AM
I'm assuming that you're in Eziefe's 140 class? If so, you can meet me in the Java lab tomorrow morning at around 11:30 and I'll give you a hand. I should have a large pair of headphones on. Just ask people if they're "jake".
Bite me.

No, Really. Bite me.

All times are US/Eastern
Hop To: