Skip to content

Instantly share code, notes, and snippets.

@DamianZaremba
Created May 11, 2011 03:33
Show Gist options
  • Save DamianZaremba/965872 to your computer and use it in GitHub Desktop.
Save DamianZaremba/965872 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void main () {
char[] queue_dir = "/home/damian/test/%s";
char *file_name = get_filename();
char file_path[strlen(queue_dir) + strlen(file_name)];
sprintf(file_path, queue_dir, file_name);
FILE *fh;
fh = fopen(file_path, "w");
fprintf(fh, "%s", "Oh hai");
fclose(fh);
}
char get_filename() {
srand(time(0));
static const char text[] = "abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789";
char file_name[54];
int i, len = rand() % (49);
for ( i = 0; i < 50; ++i ) {
file_name[i] = text[rand() % (sizeof text - 1)];
}
file_name[51] = '.';
file_name[52] = 'd';
file_name[53] = 'a';
file_name[54] = 't';
file_name[50] = '\0';
return file_name;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment