|
From: Neszt T. <ne...@ss...> - 2003-07-09 06:30:44
|
Hello!
I have a problem. First of all, see the source code:
This one is works:
/* -------------------------------------------------------------------- */
int putbuffer( /* returns 0 on success */
void *AppState,
unsigned char *buffer, /* buffer to put */
long length /* length of buffer */
) {
size_t ret;
crc = CrcUpdate(crc, buffer, length);
ret = fwrite(buffer, 1, (size_t) length, (FILE *) AppState);
if ((size_t) length != ret)
return 1;
else
return 0;
}
I tried to change it to work in memory instead of writing to file:
/* -------------------------------------------------------------------- */
int putbuffer_mem( /* returns 0 on success */
void *AppState,
unsigned char *buffer, /* buffer to put */
long length /* length of buffer */
) {
int i;
crc = CrcUpdate(crc, buffer, length);
for (i=0;i<length;i++) {
char *AppState=buffer[i]; // #1
AppState++; // #2
printf("a\n");
}
return 0;
}
This second one does nothing as I check the AppState.
Can I use (void *) to allocate memory?
The original call was
putbuffer( (void *) out, .....) ( out = fopen("name", "wb"); )
And now, I call
putbuffer_mem( mem, ....) ( mem = (char *) malloc(size); )
What would be the problem?
Is there any mode to mix the #1 and the #2 lines?
Thanks Your help in advance.
Regards,
Neszt Tibor
|