Ashwin,
I
see few problems in this code..
if ((output_file
=
fopen("output.jpg", "ab"))
1. Why are you opening the ouput file in append mode? If you run ur program more than once, the ouput file will no longer with exact replica of the original one. U wud just be appending the orig file data to the o/p file.
1. Why are you opening the ouput file in append mode? If you run ur program more than once, the ouput file will no longer with exact replica of the original one. U wud just be appending the orig file data to the o/p file.
while((fgetc(input_file))!= EOF)
2. Why aren't u assigning ur variable "c" with the value of fgetc?? The value of fgetc is going nowhere.. You are just putting in some junk in o/p file..
2. Why aren't u assigning ur variable "c" with the value of fgetc?? The value of fgetc is going nowhere.. You are just putting in some junk in o/p file..
Use:
while( (c = fgetc(input_file)) !=
EOF)
3.
You
forgot to close input file handle..
Cheers,
Amol
-----Original Message-----
From: ashwin mittal [mailto:[EMAIL PROTECTED]
Sent: 25 October 2004 17:29
To: C,C++ programming
Subject: (PT) Image File
Hi everybody,
I want to copy one picture (i.e. in gif format) to
other gif format file through C.
I dont want the copy command in C....
But the thing I want is through the file handling in C
and reading the contents and then copying the contents
to other file..
But that other file doesnt have any picture but the
size of that copied file is absolutely perfect..
Check this code and please tell me where I am wrong...
#include<stdio.h>
#include<conio.h>
void main()
{
int c;
FILE *output_file;
FILE *input_file;
if ((input_file = fopen("sample.jpg","rb")) ==
NULL)
{
fprintf(stderr, "Cannot read
properly\n");
}
if ((output_file = fopen("output.jpg", "ab"))
== NULL)
fprintf(stderr, "Cannot write properly\n");
else
{
while((fgetc(input_file))!= EOF)
{
fputc(c,output_file);
}
fclose(output_file);
}
getch();
}
__________________________________
Do you Yahoo!?
Y! Messenger - Communicate in real time. Download now.
http://messenger.yahoo.com
To unsubscribe : [EMAIL PROTECTED]
Yahoo! Groups Sponsor
ADVERTISEMENT
Yahoo! Groups Links
- To visit your group on the web, go to:
http://groups.yahoo.com/group/Programmers-Town/
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
To unsubscribe : [EMAIL PROTECTED]
| Yahoo! Groups Sponsor | |
|
|
Yahoo! Groups Links
- To reply to this message, go to:
http://groups.yahoo.com/group/Programmers-Town/post?act=reply&messageNum=3655
Please do not reply to this message via email. (more info)
- To visit your group on the web, go to:
http://groups.yahoo.com/group/Programmers-Town/
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
==============================================================================
This message is for the sole use of the intended recipient. If you received
this message in error please delete it and notify us. If this message was
misdirected, CSFB does not waive any confidentiality or privilege. CSFB
retains and monitors electronic communications sent through its network.
Instructions transmitted over this system are not binding on CSFB until they
are confirmed by us. Message transmission is not guaranteed to be secure.
==============================================================================
