help on putting different image type 
Author Message
 help on putting different image type

I have been writing a program to display a gif on the computer screen.  However
when I compile it, the picture does not show up.  Here's the source code:

void Open_Show(HDC DC, int x, int y)
{
  char buf[BUFSIZ];
  FILE *fp;
  if((fp=fopen("c:\\pics\\mybmp.gif", "r+"))==NULL)
  {
    MessageBox(HWindow, "Can't open file!", "Error", MB_OK);
  }
  fseek(fp, 776L, SEEK_END);
  fread(buf, sizeof(char), 1, fp);
  fprintf(fp, "%c");

Quote:
}

Does anybody know what's wrong with this code?  

Royous




Mon, 13 Nov 2000 03:00:00 GMT  
 help on putting different image type


Quote:
>I have been writing a program to display a gif on the computer screen.
However
>when I compile it, the picture does not show up.  Here's the source code:

>void Open_Show(HDC DC, int x, int y)
>{
>  char buf[BUFSIZ];
>  FILE *fp;
>  if((fp=fopen("c:\\pics\\mybmp.gif", "r+"))==NULL)
>  {
>    MessageBox(HWindow, "Can't open file!", "Error", MB_OK);

This function call indicates that your questions have to do with Windows
programming.

Quote:
>  }
>  fseek(fp, 776L, SEEK_END);

Rather bizarre seek to a magic position.  A comment on what you expect this
to accomplish would be in order.  Always check the return value of functions
that supply them.  [OK, maybe not printf()].

Quote:
>  fread(buf, sizeof(char), 1, fp);

You tried to read one [1] count-it "a" single, solitary character.  You did
not check the status of the seek, or the status of the read.  Since you have
no idea if either worked, what do you expect a sensible result to be?

Quote:
>  fprintf(fp, "%c");

OK, where is the character you are trying to print, and why are you writing
it back to the file you read it from?

Quote:
>}

>Does anybody know what's wrong with this code?

0.  Invest in a good lint.  Or at least turn your compiler warnings on.

1.  Post windows programming questions to windows newsgroups.
--
Hypertext C-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-FAQ ftp: ftp://rtfm.mit.edu, C-FAQ Book: ISBN 0-201-84519-9
Try "C Programming: A Modern Approach" ISBN 0-393-96945-2
Want Software?  Algorithms?  Pubs? http://www.infoseek.com



Mon, 13 Nov 2000 03:00:00 GMT  
 help on putting different image type


Quote:
> void Open_Show(HDC DC, int x, int y)

'HDC' is not defined. 'DC' is never used.

Quote:
> {
>   char buf[BUFSIZ];

'BUFSIZ' is not defined.

Quote:
>   FILE *fp;

'FILE' is not defined. (Where is <stdio.h>?)

Quote:
>   if((fp=fopen("c:\\pics\\mybmp.gif", "r+"))==NULL)

'fopen()' has not been prototyped.

Quote:
>   {
>     MessageBox(HWindow, "Can't open file!", "Error", MB_OK);

'HWindow' and 'MB_OK' are not defined. 'MessageBox()' has not been prototyped.

Quote:
>   }
>   fseek(fp, 776L, SEEK_END);
>   fread(buf, sizeof(char), 1, fp);

You might want to check the return values of these two functions.

Quote:
>   fprintf(fp, "%c");

You have not given 'fprintf()' anything to print!

The file is never closed, and the file pointer is lost when the function
returns; this is a bad thing.

Other than that, it's a wonderfully well-written function. Be proud.

--
(initiator of the campaign for grumpiness where grumpiness is due in c.l.c)

Attempting to write in a hybrid which can be compiled by either a C compiler
or a C++ compiler produces a compromise language which combines the drawbacks
of both with the advantages of neither.



Mon, 13 Nov 2000 03:00:00 GMT  
 help on putting different image type



Quote:

>> void Open_Show(HDC DC, int x, int y)

>'HDC' is not defined. 'DC' is never used.

>> {
>>   char buf[BUFSIZ];

>'BUFSIZ' is not defined.

>>   FILE *fp;

>'FILE' is not defined. (Where is <stdio.h>?)

<stdio.h> would define BUFSIZ too.

--
-----------------------------------------


-----------------------------------------



Mon, 13 Nov 2000 03:00:00 GMT  
 help on putting different image type

...

Quote:
>> void Open_Show(HDC DC, int x, int y)
>> {
>>   char buf[BUFSIZ];
>>   FILE *fp;
>>   if((fp=fopen("c:\\pics\\mybmp.gif", "r+"))==NULL)

I would expect GIF files to be in a binary format so you should open them
as binary files, with a mode such as "r+b".

Quote:
>>   {
>>     MessageBox(HWindow, "Can't open file!", "Error", MB_OK);
>>   }
>>   fseek(fp, 776L, SEEK_END);
>>   fread(buf, sizeof(char), 1, fp);
>>   fprintf(fp, "%c");
>> }

>> Does anybody know what's wrong with this code?


><snip>
>> <stdio.h> would define BUFSIZ too.

>Yes, but would it be what he wanted?

>From section 4.9.1 of the ANSI standard (havn't got ISO section):-

>"BUFSIZ
>which expands to an integral constant expression, which is the size of the
>buffer used by the setbuf function."

>Which doesn't seem to have a lot to do with fread(). Yes I *know* you knew
>that but RoyousZ may not have appreciated it.

There isn't enough information to decide whether it is appropriate or not.
The main uses of BUFSIZ would be to allocate a buffer of a reasonable
size to pass to setvbuf() or to define a reasonable sized buffer for the
processing of data in a block buffered fashion (where BUFSIZ is hopefully
optimised in some way for the platform in question). The particular
fread() here only reads one byte so BUFSIZ will be large enough to hold it.

--
-----------------------------------------


-----------------------------------------



Wed, 15 Nov 2000 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Globals in different files, different types, same names

2. Different value when converting into different type

3. Using types in a different assembly given that the type may be used or not used

4. Help w/ different types of input

5. HELP - passing different types

6. using different locales with time_put::put

7. Can you put an image into C?

8. Putting a BGI image into my DOS program

9. Putting images from C on MSDOS screen

10. Putting a rotatable 3D image in dialog box

11. putting images into a cell of a msflxgrd controll

12. Putting an image in a std::string variable?

 

 
Powered by phpBB® Forum Software