Posts

Segmentation Fault : behind the code

Segmentation fault Segmentation fault (core dumped) Did you just look at your laptop and said, "This is it buddy, don't check my patience, you are going to get hurt !!!" . If you are in this situation, then just try to understand the concept behind segmentation fault and forget the headache ;-) Segmentation fault is the exception which occurs when a program tries to access an invalid memory.  In simple words, it means accessing a memory which does not belong to you or you do not have authorization to access it.  To resolve this, you must know about GNU Debugger(GDB) , but if you are SHORT OF TIME  then first try following example: 1  #include<stdio.h> 2  int main() 3  { 4   int *p; 5   *p= 7; 6   printf("Output = %d\n",*p); 7  }  If we run this program, we will get Segmentation fault: user@gene-laptop:~$ gcc -g segment.c user@gene-laptop:~$ ./a.out Segmentation fault (core dumped) Th...

bash: ./a.out Permission denied

 bash: ./a.out Permission denied  sh: ./a.out Permission denied   Huh! Why the hell it is giving this error. It was working just fine previously. Reason 1: So, you may get this error sometime. I found this one when i tried to execute my executable file (a.out) on one of my friend's computer. When i checked it out thoroughly, I found out that normally in every executable file, there is a tab in properties of files. That tab is "Permissions". There is an option "Execute : Allow executing file as program". Just mark it true :-). a.out -> Right Click -> Properties -> Permissions -> Allow executing file as program Reason 2: Try running the file as root. You may not have permission to run the file, using sudo might work or change the permissions by using chmod . Note: This error might occur due to some other problems. I wrote this article in order to help those who have situations as described above. But please mention here if this kind of error is no...

error: stray '\' in program

 stray.c:6: error: stray '\315' in program   stray.c:7: error: stray '\242' in program   stray.c:8: error: stray '\234' in program  If you are getting error messages like above in your C/C++ program, then don't worry. ;-) Perhaps you have copied the code from somewhere. If your code is small ,then the simplest solution is that you should start typing it from zero. That is , delete all the code ( the lines you know you have copied) and re-type it. If your code is lengthy and you do not want to type it, then you should use this software : Hex Editor Wiki You may be wondering that why this problem even occurred. The reason for this is that your code might contain some hidden octal (not-readable) characters which the compiler cant understand and you can not see. They are present in your code because you have perhaps copied it from somewhere. So, simply you can retype the same code to solve the problem. ----- Happy Coding :-)

GNU Debugger(GDB)

GNU Debugger (GDB) is a debugging tool which helps in debugging c/c++ programs on Linux platform. Suppose you are writing a program and you want to trace the control flow of functions, then GDB is the answer.Though it's functionality is not only limited to this , you can also use GDB to add breakpoints ,to know that how the value of a variable is changing at run time, to trace the system calls ,library functions etc. Do not get confused because of so many new terms. Each term has been explained below. Consider a scenario of you visiting your friend's house.You got ready, took your car and you are on the road. Generally it takes an hour to reach at your friend's. But today there is a police check post blocking the road. The police officers are searching each and every vehicle to solve a robbery case just happened in the city.They do not want the thief to leave the city. So they stopped you also, then checked your identification, searched your vehicle and then cleared you....