Reputation: 117
In a function, I created the following char array.
char key1[500]="";
I am looping through index "i" in the function and copying values of inputFileArray which is a global variable through an index initialIndex (a global index).
key1[i++]= inputFileArray[initialIndex++];
This statement is resulting in error Segmentation Fault(core dumped) when I run.
BTW, this worked fine on another machine in which I compiled using visual studio c++ editor. I get this error when I try to run this on a ubuntu 13.10 on virtual machine. Appreciate your answers.
Upvotes: 1
Views: 2703
Reputation: 213879
This statement is resulting in error Segmentation Fault(core dumped) when I run.
Learn to use a debugger (usually GDB on Linux). You may want to start here.
Run your program under debugger, and verify that i < 500
and that
initialIndex < sizeof(inputFileArray)
.
this worked fine on another machine
Yes, bugs are often like that: code that works fine (appears to work fine) on one machine crashes on the next.
Upvotes: 2