Jump to content

creating dummy files(C++)


Recommended Posts

Guest gilgamesh
Posted

i need to know how to add information to a ( .dat ) file from the run of my program, but i have to create a dummy file to prevent the information on my file from being deleted when i add new information to it. could any of you tell me how to make a dummy file, and add information so nothing is lost so i can add information during the run?

  • 3 weeks later...
Guest SyntaXVB5
Posted

Can't you just write-protect the file :-\

Code-wise I could help you if you were more specific.

  • 4 weeks later...
Guest Syntax
Posted

I'm sorry I've been this late, and you probably dont even come to this thread any more but here goes code to create a simple dummyfile.

 

I had to sacrifice file size, for speed in this program. (the mass usage of the character X). Shouldn' tbe too big though.

 

/* Science Forums -- Keep it open source, pigs */

 

#include <stdio.h>

#include <stdlib.h>

 

void cls();

 

int main(void)

{

 

unsigned long c;

char d[18] = "dummyfile";

printf("DummyFile 0.7A, Matt Dunleavy\n");

printf("File Size (KB): ");

scanf("%d", &c);

printf("Please Wait...\n");

 

/* Beginning of File I/O */

FILE * dummyfile;

dummyfile = fopen(d, "w");

/* End of File I/O */

 

for (signed short int i = 1; i<c+1; i++)

{

fprintf(dummyfile, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");

}

cls();

fclose(dummyfile);

printf("Dummy File Created!\n");

return 0;

}

 

void cls()

{

system("cls"); /* uses the system command to clear the screen */

}

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.