Hi,all
I use the following code to read 10000 bytes from a file(fp1) and write
them to another file(fp2).
char *pStr = new char[10001];
fread(pStr,dw_s ize,1,fp1);
int i = 0;
while(i<10000)
{
fwrite(pStr,1,1 ,fp2);
pStr++;
}
I found only 1682 bytes was written to fp2!
Could any body tell me why?
Thanks in advance!
Anderson 2 868
I use the following code to read 10000 bytes from a file(fp1) and write
them to another file(fp2).
char *pStr = new char[10001];
fread(pStr,dw_s ize,1,fp1);
what is the value of dw_size here?
int i = 0;
while(i<10000)
{
fwrite(pStr,1,1 ,fp2);
pStr++;
}
1) i never changes, so this is an endless loop. Is this really the all of
the code in your function?
2) you write 1 byte at a time. why not write the whole buffer at once?
>
I found only 1682 bytes was written to fp2!
Apart from the things I already mentioned, You really should check the
return values that you get from the different IO functions. how else would
you know if there was a problem or not?
--
Kind regards,
Bruno. br************* *********@hotma il.com
Remove only "_nos_pam"
Thanks Bruno for metioned these points!
"Bruno van Dooren" <br************ **********@hotm ail.comдÈëÏûÏ¢
news:95******** *************** ***********@mic rosoft.com...
> I use the following code to read 10000 bytes from a file(fp1) and write them to another file(fp2).
char *pStr = new char[10001]; fread(pStr,dw_s ize,1,fp1);
what is the value of dw_size here?
> int i = 0; while(i<10000) { fwrite(pStr,1,1 ,fp2); pStr++; }
1) i never changes, so this is an endless loop. Is this really the all of
the code in your function?
2) you write 1 byte at a time. why not write the whole buffer at once?
>> I found only 1682 bytes was written to fp2!
Apart from the things I already mentioned, You really should check the
return values that you get from the different IO functions. how else would
you know if there was a problem or not?
--
Kind regards,
Bruno. br************* *********@hotma il.com
Remove only "_nos_pam" This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Hans |
last post by:
Hello,
Why all C/C++ guys write:
const char* str = "Hello";
or
const char str = "Hello";
|
by: wallacej |
last post by:
Does anybody know why
unsigned char myImage; works but
unsigned char myImage; does not?
I think its because the second line is a value too big for unsigned
char, is this correct?
If so:
|
by: Roy Hills |
last post by:
When I'm reading from or writing to a network socket, I want to use a
struct to represent the structured data, but must use an unsigned char
buffer for the call to sendto() or recvfrom().
I have two questions:
1. Is it generally safe to "overlay" the structure on the buffer,
e.g.:
unsigned char buffer;
|
by: electric sheep |
last post by:
Hi, can somebody explain the following syntax to me.
This is straight from a gnu info file:
int
main(void)
{
/* Hashed form of "GNU libc manual". */
const char *const pass = "$1$/iSaq7rB$EoUw5jJPPvAPECNaaWzMK/";
I think the idea at play here is whether the pointer is constant or not ?
|
by: Johnathan Doe |
last post by:
Why is is necessary to write a function that allocates memory for, or
changes, a pointer to a char array using char** instead of char*?
E.g.
void modify_string( char** string )
{
if( string == NULL )
return;
| |
by: Rookie |
last post by:
I was just reading about the envp argument for main function. Since
there is no argc equivalent for envp (i.e the number of elements for
the envp array are not known) the last element will be a null pointer.
But my question is about the syntax used to test this:
envp!=(char *)0
!=(char *)0;i++)]
What exactly does (char *)0 stand for?...
|
by: ravinderthakur |
last post by:
hi all experts,
can anybody explain me the difference between the
unsigned char and char in c/c++ langugage.
specifically how does this affects the c library fucntion such as
strcat,strtok etc and
their implementation.the way compiler treats them and the scenarios
where one
|
by: aarklon |
last post by:
Hi all,
this is a question which i saw in a book
typedef struct mall_li_header_ {
int refcnt;
uchar pool;
uchar flag;
ushort magic_no;
char data;
|
by: dtschoepe |
last post by:
Hi,
I have a homework project I am working on, so be forwarned, I'm new to
C programming. But anyway, having some trouble with a memory
allocation issue related to a char * that is a variable inside of a
structure. I keep getting segmentation fault errors and I am having
trouble understanding why. Here's the parts of the code in question......
|
by: arnuld |
last post by:
i see the use of pointers, from K&R2 but what is the use of:
1. "pointer to pointer":
char c;
char** ppc;
2. pointer to function:
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |