Question:
C Question: File Extensions?
Jamie
2011-06-30 11:30:33 UTC
Hi,

I'm using custom file extensions with my programs, such as .jre and .enf, which I have not had any problems with so far while using Java, but I can't seem to read from these with my C programs. Can C only open certain file extensions? I'm using the same code, but changing the file name and my program works fine with a .txt extension, but crashes with the use of the other file extensions.

So, can someone explain to me why its not working?

Thanks
Four answers:
Don't sue me!
2011-06-30 11:42:51 UTC
I wouldn't recommend using a custom extension since it makes your files and code harder to understand, though reading files with custom extension is completely IDE or compiles independent.

You could try another editor, a good editor is code::blocks or mingw, although I haven't tried them.

I use MS VC++.
RatTomago
2011-06-30 11:39:44 UTC
C can open any file extension. Is it possible that your windows explorer could be hiding file extensions though? For instance your file could appear to be called "foo.enf" but its real name is "foo.end.txt". Make sure you are viewing file extensions. This could be causing your file pointer to be null because you didn't actually open the file and you are not checking for a null pointer exception.
?
2011-06-30 11:39:37 UTC
C really does not care. libc open() or fopen() would open any existing file, regardless of the name.

UPDATE: use your debugger. Put a breakpoint at your fopen() call. Check the value returned by fopen(). Put a breakpoint at your first fgets() and check the value of your file pointer BEFORE you step over the fgets().
?
2017-01-21 18:15:27 UTC
The report extension in C is .c like attempt.c and in C++, the extension of report is .cpp, like attempt.cpp. The printf and scanf are the widely used output and enter instructions in C. yet those could nicely be valid in C++. the comparable instructions are cout and cin products respectively in C++.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...