[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: debugging



Felix Kollmann schrieb:

> I the file which is attached is a extract of the function to open the
> file.

> int def_config::open (char name [255])

If I´m not completely wrong this will just pass a pointer to an array of
char - not the array itself. And the "255" is completely irrelevant.
Nothing serious here though.

> {
>   FILE *datei;
>   char zeile [255];
> 
>   if (!(datei= fopen ("jumpnodes.conf", "r")))
>   {
>     printf ("Fehler beim Öffnen der Datei '%s' :\n", name);
>     perror (name);
>     printf ("------- Fehler\n\n");
>     exit (1);

This error messages are not printed, right? That means the file is
opened correctly (for reading, as text).

>   } else
>   {
>     printf ("Öffne Datei '%s' :\n",name);
>   }
> 
>   while (fgets (zeile, 255, datei))
>   {
>     fscanf (datei, zeile);

Stop - you first read a string (up to 255 characters) into "zeile". Then
you use that string you just read as format string for fscanf - and omit
the other fscanf parameters you need.
Have a look at the fscanf docs again. 

>     if (!(zeile=="\n")) { konsole.do_command (zeile); }

The "zeile == "\n"" is wrong. You compare the pointer named "zeile" with
the pointer to the constant "\n". For string comparisons you have to use
strcmp () (or the std string class).


	Christian