C Programming fopen() while opening a file -
i've been wondering one. books i've read shows when open file , found file not existing, should put error there's no such file exit system...
file *stream = null; stream = fopen("student.txt", "rt"); if (stream==null) { printf(“cannot open input file\n”); exit(1); else {printf("\nreading student list directory. wait moment please..."); but thought instead of doing that.. why not automatically create new 1 when found file opening not existing. if not writing on file upon using program (but use next time). i'm not sure if efficient or not. i'm new here , have no programming experience whatsoever i'm asking opinion advantages , disadvantages of creating file upon trying open instead of exiting system being exampled on books.
file *stream = null; stream = fopen("student.txt", "rt"); if (stream == null) stream = fopen("student.txt", "wt"); else { printf("\nreading student list directory. wait moment please..."); your opinion highly appreciated. thank you.
because from example, seems it's input file, if doesn't exist, no point creating it.
for example if program supposed open file, count how many vowels in it, don't see sense of creating file if doesn't exist.
my $0.02 worth.
Comments
Post a Comment