fwrite problem
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: fwrite problem

  1. #1
    Join Date
    Apr 2013
    Posts
    77

    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
    HTML Code:
    INPUT
    Output iam getting
    HTML Code:
    I[NULL]N[NULL]P[NULL]U[NULL]T[NULL]

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,392

    Re: fwrite problem

    Is your build a UNICODE one?
    Victor Nijegorodov

  3. #3
    Join Date
    Apr 2013
    Posts
    77

    Re: fwrite problem

    Quote Originally Posted by VictorN View Post
    Is your build a UNICODE one?
    yes sir

  4. #4
    Join Date
    Apr 2013
    Posts
    77

    Re: fwrite problem

    So for getting desired output i should use char array instead of TCHAR array.Am i Correct?

  5. #5
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,391

    Re: fwrite problem

    Quote Originally Posted by manjut19 View Post
    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. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  6. #6
    Join Date
    Apr 2013
    Posts
    77

    Re: fwrite problem

    Quote Originally Posted by 2kaud View Post
    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()
    ?

  7. #7
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,391

    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. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center