I just copied and pasted all the things that has been happening from the shell here:

lin309-05:~/workspace/acm$ gdb a.out
GNU gdb (GDB) 7.1-ubuntu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /.../workspace/acm/a.out...done.
(gdb) break main
Breakpoint 1 at 0x400f8f: file 156.c, line 164.
(gdb) r
Starting program: /.../workspace/acm/a.out 

Breakpoint 1, main () at 156.c:164
164		freopen("input.txt", "r", stdin);
(gdb) n
168			scanf(" %s", dictionary[i]);
(gdb) n

[B]Program received signal SIGSEGV, Segmentation fault.
_IO_vfscanf_internal (s=0x7ffff76296a0, format=<value optimized out>, argptr=0x6c, errp=<value optimized out>) at vfscanf.c:1053
1053	vfscanf.c: No such file or directory.
	in vfscanf.c[/B]
(gdb) q
A debugging session is active.

	Inferior 1 [process 4610] will be killed.

Quit anyway? (y or n) y
lin309-05:~/workspace/acm$ ls input.txt
input.txt

The code is below:

int main()
{	
	char dictionary[DIM_DICT][500];
	sign signature[DIM_DICT];
	int n;
	int i;
	int j;
	int k;
	int count;
	char output[DIM_DICT][500];

	freopen("input.txt", "r", stdin);

	while (1)
	{		
		scanf(" %s", dictionary[i]);
		if (!strcmp(dictionary[i], "#"))
		{
			break;
		}
		gen_signature(signature, dictionary, i);
		n++;
		i++;
	}
        ...
}

This doesn't make sense. I used gdb just yesterday. And the problemetic line is

scanf(" %s", dictionary);

dictionary is an array of strings. So what's wrong?

i is probably greater than DIM_DICT

but why this?

_IO_vfscanf_internal (s=0x7ffff76296a0, format=<value optimized out>, argptr=0x6c, errp=<value optimized out>) at vfscanf.c:1053
1053	vfscanf.c: No such file or directory.
	in vfscanf.c

gdb is supposed to be managed environment where it has a view and control of where is what going. If it is sensing an array out of bound exception it can signal it instead of bullshitting around.

gdb just shows you where it crashed - inside some internal routing of scanf.

Use the bt command to see the stack trace, and 'up' and 'down' to navigate the stack until you get to a line of YOUR code.

Then examine the variables.
i is a good bet for being out of range of your array.

WaltP is almost certainly right, you walked off the end of your array with your while true loop.

Try while ( i < DIM_DICT ) instead.

Neither did you initialised i nor did you checked for the end condition.
In your case since i is not initialised which have some garbage value and you are trying to access dictionary, which obviously will give u a segfault.
Also, since you didn't put an end condition, the loop will go infinite......

Hope this helps in solving your proble.

Thanks guys for your replies. I think I did 2 mistakes that contributed to this: 1 I put the array inside the function instead of making it global. secondly while experimenting I choose the DIM_DICT small enough that caused buffer overflow. So I think your suggestions was right for the second thing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.