simple solution -- move lines 28 and 42 up to line 7 so that its scope is to the entire function. Also you can't declare a matrix using non-static number of elements. If you don't know the size of the matrix at compile time then you have to allocate the dimensions with malloc()
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
> for (p = 1; p <=2; p++)
Arrays start at subscript 0, not 1.
You're trashing all over someone else's memory, hence the segfaults at some point.
Given an array of size N, the normal loop would be for ( i = 0 ; i < N ; i++ )
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
also, learn to use c++ cin and cout to simplify your code. you can replace printf() with cout and scanf() with cin.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
Oops! my error -- you are correct that you can not use cin and cout in C. I had c++ in mind. Sorry for that gaff. :icon_redface:
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343