c programming :searching a sub string in a string
I was studying this code and got a segmentation fault .Please help me with this ..
Code:
#include<stdio.h> |
Never use gets().
Quote:
Quote:
Compile your program with gcc -ggdb and than run it through gdb: Code:
$ gcc -ggdb -o example example.c |
Quote:
Since the code wouldn't even compile, the reported seg fault is hard to explain. With correct input the program adjusted just enough to compile then works correctly and does not seg fault. Rather than just tell someone never use gets() it is better to explain that when the input is longer than the buffer, gets() will corrupt memory with almost any result possible, including seg fault. Then the beginner writing the code can decide whether input longer than buffer is a condition he chooses to worry about. |
All times are GMT -5. The time now is 03:09 PM. |