Skip to main content
2 of 5
further clarification of topic
Dexter Thorn
  • 2.2k
  • 2
  • 22
  • 37

Overwrite disk space for the purpose of deleting old data

I have written a little program that overwrites memory. It creates useless files in a folder named "folder" (I am so creative). The purpose is to overwrite old data. It's not a very professional program because I am a beginner, but I think it should do for which it is destined: exhaust memory and thus maybe overwrite old data that was stored on it. If you have tips for me how to imrove this program or how to make it faster in it's execution I would be thankful!

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

int create_files(int number_of_files, int number_of_values);

int main()
{
    int i;
    int number_of_files;
    int number_of_values;
    
    printf("before using this program create a folder named \"files\"\nin the same folder this program is located\n");
    printf("number of files: ");
    scanf("%d", &number_of_files);
    printf("number of values: ");
    scanf("%d", &number_of_values);
    
    create_files(number_of_files, number_of_values);
    
}

int create_files(int number_of_files, int number_of_values)
{
    srand(time(NULL));
    
    for(int i = 0; i < number_of_files; i++)
    {
        FILE * file;
        char file_name[30] = "./folder/";
        char file_number[20];
        sprintf(file_number, "%d", i);
        strcat(file_name, file_number);
        file = fopen(file_name, "w+");
        
        for(int j = 0; j < number_of_values; j++)
        {
            int random_value = rand();
            fprintf(file, "%d", random_value);
        }
        fclose(file);
    }
}
Dexter Thorn
  • 2.2k
  • 2
  • 22
  • 37