Hi there!

On Sun, 3 Jan 1999, Catalin Bucur wrote:

> Hello and Happy New Year,

Nod. Grin, same to you :)

> The program is simple, so what is the problem? I don't have the right memcpy.c
> file, or it's an error on 40 line of memcpy.c?

The problem seems to be the fact that buf is a uninitalized pointer 
probably pointed to garbge...

> ----------------------------------------------------------------------------
> // My program
> 
> #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);

Hrm, actually, I'm surprised this line didn't give you trouble either...

You need to have word and buf pointing to something....

Before using either pointer, say something like this:

   word = malloc(dim);
   buf = malloc(dim);

Note you'll have to #include <stdlib.h> to have malloc's prototype

And you'll have to call free() later probably :)

>   if ((f = fopen("//misc//dos//cpp//english//dict_er", "rb")) == NULL)

You don't need to double the frontslash, only the backslash because it's 
that special escape char...

Linux is cool enough to let you do this (try typing "cat 
//////etc//////passwd" and it'll still work :)

>   {
>      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.

Nod, I think the problem is with buf being uninitalized...

>   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 !?!

Hrm, I'm not sure about this... I usually keep reading until I get a zero 
returned from read() (or fgets)... Somebody else might be able to help 
you out here....

Best of luck to you :)

-Brett

Reply via email to