Aria
As said by Ion, it is a problem with the usage of the pointer 'x'. Given that code, I don't see a memory allocation done to that pointer. Its failing due to that and not releated to int i=0, etc.
U must be have a malloc call for x before using it.
Check that.
IF u are still confused, send...