Beginner, stuck on a function problem - Tearing out hair...

This is a discussion on Beginner, stuck on a function problem - Tearing out hair... within the C Programming forums, part of the General Programming Boards category; Hello,
I'm an absolute beginner to C. I am studying a module of C programming at University after studying and ...

Beginner, stuck on a function problem - Tearing out hair...

Hello,

I'm an absolute beginner to C. I am studying a module of C programming at University after studying and becoming proficient at Java. I've learn a lot from the examples we have been given, and unerstand how close C and Java are, so I cannot understand why the fucntion "display" in this simple piece of code will not run. When execute, the program reaches this point and stops.

Please don't laugh if I have made some kind of monumental error, my head is swimming and I'm just about ready to scream...

Basically, the array holds 100 distances between 10 points.
Instead of having to enter all 100 points, the user enters 50 points and that piece of code mirrors these points from one side to the other (as the distance between points 1 and 3 is the same as between 3 and 1).

That piece of code appears to work fine. It does not give any errors when compiled using Unix, Visual Studio or Turbo C.

Basically, the array holds 100 distances between 10 points.
Instead of having to enter all 100 points, the user enters 50 points and that piece of code mirrors these points from one side to the other (as the distance between points 1 and 3 is the same as between 3 and 1).

That piece of code appears to work fine. It does not give any errors when compiled using Unix, Visual Studio or Turbo C.

But I am interested to lear nwhat you mean by a segment error??

Thanks

A segmentation fault ("seg fault" for short) is when you try to access some memory that is not allocated to your process.

If you have:

Code:

int a[10];

and you write an int into a[10] (remember index is 0-based, so your last array member is a[9]), you may trash other memory in your process, or you may seg fault.

Bottom line, in C you have to be very careful with arrays and memory in general.