Hi Happy New Year
I think U R not allocating the memory to the
pointer "buf" but using buf to get some data.
This is an error as buf may be pointing to some
illegal segments of data.
#include "malloc.h"
#define MAXDATA 2096
and add this line before the line gets(buf ....
buf = malloc(MAXDATA);
Hope this solves your error.
(Do allocate memory for word also)
cheers,
Suresh Reddy
Wipro-Nortel Networks
Bangalore
>Hello and Happy New Year,
>
>I have a problem with a program which running well in DOS, but not at all under
>Linux. I used (for the first time) gdb, and this happened:
>-----------------------------------------------
>Program received signal SIGSEGV, Segmentation fault.
>0x40053cee in memcpy (dstpp=0x1, srcpp=0x400b6000, len=120)
> at ../sysdeps/generic/memcpy.c:40
>../sysdeps/generic/memcpy.c:40: No such file or directory.
>(gdb) next
>Program terminated with signal SIGSEGV, Segmentation fault.
>The program no longer exists.
>-----------------------------------------------
>#include <stdio.h>
>#include <string.h>
>
>const dim=123;
>
>FILE *f;
>int i;
>
>int main()
>{
> char *word, *buf;
> char en[41], rom[81];
> unsigned long t;
>
> printf("WORD: ");
> scanf("%s",word);
>
> if ((f = fopen("//misc//dos//cpp//english//dict_er", "rb")) == NULL)
> {
> fprintf(stderr, "Cannot open input file.\n");
> return 1;
> }
>
>// Here, if a comment the following three lines, the program works fine.
>// I have tried fread instead of fgets, but the same result.
> do
> fgets(buf, dim+1, f);
> while(strncmp(buf,word,strlen(word)));
>
> if ((t=ftell(f)) <= dim*9)
> fseek(f, 0, SEEK_SET);
> else
> fseek(f, -dim*9, SEEK_CUR);
>
> do
> {
> fread(en, 41, 1, f);
> printf("| %.25s| ",en);
> fread(rom, 81, 1, f);
> printf("%.50s|",rom);
> fseek(f, 1L, SEEK_CUR);
> }
> while( (ftell(f) < t+dim*8) && strncmp(en,"zuc",3) );
>// Here I want to put while(... && !feof(f));
>// but the program running and running...
>// and doesn't stop !?!
>
> fclose(f);
> return 0;
>}
>----------------------------------------------------------------------------
>
>Thanks,
>Cata.
>
>--
>=/^\_/^\_/^\_/^\_/^\_/^\_/^\_/^\_/^\_/^\_/^\_/^\=
>\ Don't believe all you hear, /
>/ spend all you have, \
>\ or sleep all you want. /
>/=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\
>\ Catalin Bucur, /
>/ Hardware engineer mailto:[EMAIL PROTECTED] \
>=/^\_/^\_/^\_/^\_/^\_/^\_/^\_/^\_/^\_/^\_/^\_/^\=
>
--