vs2017 AND Fwrite

Feb 4, 2018 at 8:49pm
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);
    	

Feb 4, 2018 at 8:58pm
closed account (E0p9LyTq)
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
Feb 4, 2018 at 9:15pm
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.

Feb 4, 2018 at 9:28pm
closed account (E0p9LyTq)
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.
Feb 4, 2018 at 9:44pm
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?

Feb 4, 2018 at 9:48pm
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;



Feb 4, 2018 at 9:57pm
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.
Feb 4, 2018 at 10:10pm
Why is fwrite giving me a error before i even compile
Last edited on Feb 7, 2018 at 10:36pm
Feb 4, 2018 at 10:19pm

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 Feb 4, 2018 at 10:20pm
Feb 10, 2018 at 7:31pm
another dumb mistake
for some reason the was a int fwrite=0; in my code
Topic archived. No new replies allowed.