2016-05-06 5 views

Antwort

0

Dateiname nicht akzeptabel sein kann, oder eine Genehmigung Problem leben.

Try this:

#include <string.h> 
#include <errno.h> 

void my_create(char* path) 
{ 
    FILE* fp; 
    fp = fopen(path, "rb+"); 
    if (fp == NULL) { /* File doesn't exist*/ 
     printf ("File does not exist : %s", path) 
     fp = fopen(path, "wb+"); 
     if (fp == NULL) { 
      fprintf (stderr, "Cannot create file : %s\n", path); 
      fprintf (stderr, "Reason : %s" , strerror (errno)); 
     } 
    } 
} 
+0

Verwenden Sie "perror" oder "strerror", um das Problem zu diagnostizieren. –

0

Ich denke nicht, Dateiprüfung existiert oder nicht mit fopen ist der richtige Weg. Sie können stat() verwenden.

struct stat st = {0}; 
if (stat(path, &st) == -1) 
{ 
    FILE *fp = fopen(path, "w+"); 
    if (!fp) printf("Can not create file: %d\n", errno); 
    else fclose(fp); 
} 
Verwandte Themen