how wud i go about......

chipstar
chipstar used Ask the Experts™
on
heyyyyyyyyyy!!!

im in the middle of writing a program, and am wanting now to write a function that will create a file of a certain size increasing/decreasing byte size of file.

How wud i do thissssss????????????

ne help wud be v grateful! Thanx!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
CEO/Programmer
Commented:
It is unclear to me what your problem is. Just open the file
write to it byte-by-byte after you have reached a certain count close the file.

What is the problem?

Regards
Friedrich
Yup open the file:

FILE *fp;
char fdata[10000]; //file data
int i;

fp = fopen(filename,"w");

while(i != noofbtes)
{
    putc(fdata[i],fp;
    i++;
}

Author

Commented:
the function should increase/decrease  buffer size as necessary and produce a file of a specified size. does this make it clearer?
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

buffer size does not matter,  set the buffer to 1 million if ya like,  when u have the data in the buffer u can set the number of bytes for the function to read outta the buffer in the while loop.

Commented:
may be u want this

#include <stdio.h>
#include <types.h>
typedef unsigned char byte
FILE *fp;
byte *data=NULL;
int i;
off_t size=0,newsize,finalsize;
//some how calculate initial size of file needed
fp = fopen(filename,"wb");
data=(byte*)realloc(data,size*sizeof(byte));

//now fill in whatever u wanna fill

//just now u felt like resizing ur buffer

data=(byte*)realloc(data,newsize*sizeof(byte));
fwrite(data,finalsize,sizeof(byte),fp); // this is if u wanna write raw bytes in binary format

other wise loop through the data and use putc to put each character

but still i think what fridom said is more than enough
 

Author

Commented:
its meant to be a kernel function....
Top Expert 2006

Commented:
No comment has been added lately and this question is therefore classified abandoned.

If asker wishes to close the question, then refer to
http://www.experts-exchange.com/help/closing.jsp

Otherwise, I will leave a recommendation in the Cleanup topic area that this question is:
PAQed with B grade and 50:50 split between  fridom and TDC_LuCiFeR
B grade here is due to vagueness of the question and its lower usability as a PAQ rather than expert opinion

Please leave any comments here within the next seven days. It is assumed that any participant not responding to this request is no longer interested in its final disposition.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Sunny
EE Cleanup Volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial