Jump to content

creating dummy files(C++)

Featured Replies

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...

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

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

  • 4 weeks later...

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 */

}

Archived

This topic is now archived and is closed to further replies.

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.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.