Line 14:
totalsquares is being calculated from an uninitialized variable. Declare totalsquares, and don't give it a value until AFTER the user has entered the Nsize value.
Line 20:
Same thing with calculating i and j - do that AFTER Nsize has been entered.
The malloc just seems wrong:
array = malloc(Nsize * sizeof(int*));
for(i = 0;i<Nsize;i++)
array[i]=malloc(Nsize * sizeof(int));
array[totalsquares] is never a part of the array. In C, array indices go from 0 to totalsquares - 1 only.
And I have no idea why you'd malloc an address to an int array[index], anyway.
It's always a good idea to free these malloc'd memory in their reverse order, just before your program ends.
Adak
Posting Virtuoso
1,640 posts since Jun 2008
Reputation Points: 456
Solved Threads: 196
Skill Endorsements: 7