0

I want to change size of *.txt file, which is created before. For this i use chsize. Code:

#include <iostream>
#include <stdio.h>
#include <io.h>

using namespace std;

int main()
{
    FILE *wfile; 
    wfile = fopen("test.exe", "a");
    chsize(wfile, 1024); //error is here
    file.close();
    return 0;
}

And here goes the error:

[Error] invalid conversion from 'FILE* {aka _iobuf*}' to 'int' [-fpermissive]

Q: What is wrong here? I opened the file with fopen right how it explained in the internets.

Q2: I love Windows as a OS, but I don't want to learn Windows API for C++ or something like that. Is there a option to use something portable?

Shorrer
  • 3
  • 1
  • 6

1 Answers1

3

First parameter for chsize is file descriptor not FILE*.

You can use function "fileno".

How can I convert a file pointer ( FILE* fp ) to a file descriptor (int fd)?

Community
  • 1
  • 1
Tomashu
  • 515
  • 1
  • 11
  • 20