Zitat:
kann Dateinamen nicht prüfen
|
Ein Nachteil, der sich ohne viel Muehe ausbessern laesst.
Es muss doch nicht jeglicher Schrott in Vista / W7 Style rauskommen

Nein, zum Thema GUI bin ich einfach noch nicht gekommen. Aber ich denke, dass bei so einem einfachen Generator kein richtiges Interface benoetigt wird. Trotzdem ist deine Kritik fuer das naechste Mal im Hinterkopf
Source:
Code:
#include <stdio.h>
#include <stdlib.h>
#define GB 1073741824
#define MB 1048576
#define KB 1024
void create_file(char *name, unsigned int size);
int main (void) {
unsigned int filesize;
char filename[103];
int wahl = -1;
printf("Exercise program created by skriiva\n\n");
printf("Questions or advices to [email protected]\n\n");
printf("File generator\n");
printf("Create files in each size\n");
printf("\n\nFile name: ");
scanf("%103s", &filename);
while(1) {
printf("\n\nInput format\n\n");
printf("1 - Input in GB\n");
printf("2 - Input in MB\n");
printf("3 - Input in KB\n");
printf("4 - Input in B\n\n\n");
printf("5 - Cancel\n\n");
printf("Choose: ");
scanf("%d", &wahl);
if(wahl == 5) {
printf("\n\nProgress cancelled!\n\n");
break;
return EXIT_FAILURE;
}
else {
if((wahl > 0)&&(wahl < 6)) {
printf("\n\nFile size: ");
scanf("%ld", &filesize);
if ( wahl == 1)
create_file(filename, filesize * GB);
if ( wahl == 2)
create_file(filename, filesize * MB);
if ( wahl == 3)
create_file(filename, filesize * KB);
if ( wahl == 4)
create_file(filename, filesize);
break;
}
else {
continue;
}
}
}
return EXIT_SUCCESS;
};
void create_file(char *name, unsigned int size) {
FILE *create = fopen(name, "wb");
if (NULL == create) {
fprintf(stderr, "Error: Could not create file ( Maybe lack of rights )\n");
exit(EXIT_FAILURE);
}
fseek(create, size-1, SEEK_SET);
putc('x', create);
printf("Datei erstellt!");
fclose(create);
};