-
August 17th, 2013, 02:23 AM
#1
fwrite problem
Iam trying to write a TCHAR array value to a file.But i am not getting it correctly.I should get the data continously.But iam getting Null between each character.
Code:
FILE * pFile;
TCHAR buffer[] = {"INPUT"};
fopen_s (&pFile,_T("myfile.#abc"), "w+");
fwrite (buffer , wcslen(buffer)+1, sizeof(TCHAR),pFile);
fclose (pFile);
Output i should get
Output iam getting
HTML Code:
I[NULL]N[NULL]P[NULL]U[NULL]T[NULL]
-
August 17th, 2013, 03:40 AM
#2
Re: fwrite problem
Is your build a UNICODE one?
Victor Nijegorodov
-
August 17th, 2013, 04:04 AM
#3
Re: fwrite problem
Originally Posted by VictorN
Is your build a UNICODE one?
yes sir
-
August 17th, 2013, 05:17 AM
#4
Re: fwrite problem
So for getting desired output i should use char array instead of TCHAR array.Am i Correct?
-
August 17th, 2013, 05:40 AM
#5
Re: fwrite problem
Originally Posted by manjut19
So for getting desired output i should use char array instead of TCHAR array.Am i Correct?
This depends upon what is the desired output! As it stands, you are writing 16bit unicode chars to the file. So these can be read as 16bit unicode chars. If you just want a file of 8bit ASCII chars, then buffer should be of type char (8bit ASCII) as opposed to TCHAR (16bit UNICODE).
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
August 17th, 2013, 06:26 AM
#6
Re: fwrite problem
Originally Posted by 2kaud
This depends upon what is the desired output! As it stands, you are writing 16bit unicode chars to the file. So these can be read as 16bit unicode chars. If you just want a file of 8bit ASCII chars, then buffer should be of type char (8bit ASCII) as opposed to TCHAR (16bit UNICODE).
Actually Buffer value i am getting throgh a system function call,Thats why that is aTCHAR variable.I canot change that variable.Then next option is Converting TCHAR * to char *How to do that conversion?can i use
Code:
widechartomultibyte()
?
-
August 17th, 2013, 06:32 AM
#7
Re: fwrite problem
How to do that conversion?can i use widechartomultibyte()
Yes. See
http://msdn.microsoft.com/en-us/libr...=VS.85%29.aspx
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|