vs2017 AND Fwrite

fwrite is giving me
expression preceding parentheses of apparent call must have (pointer-to-) function

1
2
3
4
5
6
7
    strcat(t5c,"\\7zip.7z");
    FILE *filedata = fopen(t5c, "w");
    char *buff = new char[c2];
    fread(buff,1 ,c2, filestringdata);
    fwrite(buff, 1, c2, filedata);
    fclose(filedata);
    	

Don't hardcode the size of a char in the fread and fwrite functions, obtain the size of a char with the sizeof() operator.

https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/fread
cant do that the data i am trying to read and write is in the middle of a big binary file
the file pointer is all ready set for the read and it read ok.

it the fwrite that give me the error in vs2017 before i even compile.

You can't change a 1 to sizeof(char)? I doubt that.

fread(buff, sizeof(char) , c2, filestringdata);

instead of

fread(buff,1 ,c2, filestringdata);

Do the same for fwrite().

Where are you getting the value for c2? Your problem could be elsewhere than fread() and fwrite(). Impossible to tell without seeing more of your code.
It really doesn't make any difference if you use sizeof(char) or 1, since sizeof(char) is always 1.

But you really should be checking to insure that the fread() actually read C2 bytes before you try to write the information to the output file.

Also why are you using C FILE instead of C++ file streams?

fread works I trace it thru the debugger
I can even comment out fread
the error still in fwrite
I can put numbers in fwrite or even size of
the error still there

[CODE]
strcat(t5c,"\\7zip.7z");
FILE *filedata = fopen(t5c, "wb");
unsigned char *buff = new unsigned char[c2];
//fread(buff,1,c2, filestringdata);
fwrite(buff, 1, 1,filedata);
fclose(filedata);
[CODE]

could it be in the include

#include "stdafx.h"
#include "Plugin.h"
#include "sample.h"
#include <bitset>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <direct.h>
#include<windows.h>
#include "Plugin.h"
#include <string>
#include <direct.h> //make directory
using namespace std;



Why is *buff now an unsigned char?

If you comment out the fread() buff will be uninitialized so you will be trying to write some unknown value to the file.
Why is fwrite giving me a error before i even compile
Last edited on

the data i am reading in is compress zip

You're not showing any information about the input file. So how are you uncompressing this zip?


doesnt really matter why is fwrite giving me a error before i even compile

So what exactly are the error messages, all of them? The picture you posted appears to be pointing to the strcat() call, but it is hard to read so I may be wrong.

By the way you are really not showing enough content. And not answering all the posed questions is not helping either.

Last edited on
another dumb mistake
for some reason the was a int fwrite=0; in my code
Topic archived. No new replies allowed.