fopen crashed when special characters found.
-
Hello everybody, i am trying to create a text file and trying to write something. my problem is with the file name. FILE *fp; fp = fopen("c:\test_1/2.txt,"wb"); this special character "/" is not accepting and fp is returning null, and it crashes the system if i try to write something in fp. i need to keep the file name as like this only. is there anyway to solve this issue? Thanks in advance. A. Gopinath.
-
Hello everybody, i am trying to create a text file and trying to write something. my problem is with the file name. FILE *fp; fp = fopen("c:\test_1/2.txt,"wb"); this special character "/" is not accepting and fp is returning null, and it crashes the system if i try to write something in fp. i need to keep the file name as like this only. is there anyway to solve this issue? Thanks in advance. A. Gopinath.
if that is a file named
test_1/2.txt
(and not file 2.txt in some test_1 folder) then the filename IS invalid. You'll have to choose a different name for your file. See here[^]. :)Luc Pattyn [My Articles] Nil Volentibus Arduum
-
Hello everybody, i am trying to create a text file and trying to write something. my problem is with the file name. FILE *fp; fp = fopen("c:\test_1/2.txt,"wb"); this special character "/" is not accepting and fp is returning null, and it crashes the system if i try to write something in fp. i need to keep the file name as like this only. is there anyway to solve this issue? Thanks in advance. A. Gopinath.
tagopi wrote:
is there anyway to solve this issue?
yeah, don't call fwrite if your fp is NULL.
-
Hello everybody, i am trying to create a text file and trying to write something. my problem is with the file name. FILE *fp; fp = fopen("c:\test_1/2.txt,"wb"); this special character "/" is not accepting and fp is returning null, and it crashes the system if i try to write something in fp. i need to keep the file name as like this only. is there anyway to solve this issue? Thanks in advance. A. Gopinath.
tagopi wrote:
is there anyway to solve this issue?
Seeing as how that file cannot be created outside of code (e.g., right-click desktop, new text document, type name), I doubt it.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
-
Hello everybody, i am trying to create a text file and trying to write something. my problem is with the file name. FILE *fp; fp = fopen("c:\test_1/2.txt,"wb"); this special character "/" is not accepting and fp is returning null, and it crashes the system if i try to write something in fp. i need to keep the file name as like this only. is there anyway to solve this issue? Thanks in advance. A. Gopinath.
I think everyone here missed the real issue here. "c:\test_1/2.txt" There is a \t in the filename, which is converted to a tab character by the compiler. The file path getting passed into
fopen
is "c: est_1/2.txt" You need to escape this backslash with another backslash, so your filename becomes "c:\\test_1/2.txt". as for the forward slash, windows will interpret this as a path slash too, but you don't need to escape it because the compiler wont change it. So, the path you are accessing is C: > test_1 > 2.txt Additionally, fopen will not create the folder "test_1" if it does not exist, it will just fail to open it and return NULL. -
I think everyone here missed the real issue here. "c:\test_1/2.txt" There is a \t in the filename, which is converted to a tab character by the compiler. The file path getting passed into
fopen
is "c: est_1/2.txt" You need to escape this backslash with another backslash, so your filename becomes "c:\\test_1/2.txt". as for the forward slash, windows will interpret this as a path slash too, but you don't need to escape it because the compiler wont change it. So, the path you are accessing is C: > test_1 > 2.txt Additionally, fopen will not create the folder "test_1" if it does not exist, it will just fail to open it and return NULL. -
That however wouldn't cause a crash. Whereas not testing the return value of the method probably does.
OK, you are correct. The return value should always be checked for success, but if the filename was valid (and this is where the real issue is) the OP probably would have never noticed that, because it wouldn't be returning NULL.
-
Hello everybody, i am trying to create a text file and trying to write something. my problem is with the file name. FILE *fp; fp = fopen("c:\test_1/2.txt,"wb"); this special character "/" is not accepting and fp is returning null, and it crashes the system if i try to write something in fp. i need to keep the file name as like this only. is there anyway to solve this issue? Thanks in advance. A. Gopinath.
Hi, You are not able to create file name having special characters like "/,\,*" etc. If you want to confirm, just go on your desktop and try to create file having name "test_1/2", OS will not even allow to type '/' in file name. Happy Programming. Regards
-
Hello everybody, i am trying to create a text file and trying to write something. my problem is with the file name. FILE *fp; fp = fopen("c:\test_1/2.txt,"wb"); this special character "/" is not accepting and fp is returning null, and it crashes the system if i try to write something in fp. i need to keep the file name as like this only. is there anyway to solve this issue? Thanks in advance. A. Gopinath.