# Why vfprintf is different in unreal engine ?

**URL:** <https://forums.unrealengine.com/t/why-vfprintf-is-different-in-unreal-engine/432787>\
**Category:** Plugins\
**Tags:** visual-c-platform-to, unreal-engine, Plugins, Visual-Studio, CPP, question\
**Created:** [August 30, 2018, 11:36am UTC](https://forums.unrealengine.com/t/why-vfprintf-is-different-in-unreal-engine/432787 "2018-08-30T11:36:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![BestWarrior](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BestWarrior](https://forums.unrealengine.com/u/BestWarrior)\
**Post date:** [August 30, 2018, 11:36am UTC](https://forums.unrealengine.com/t/why-vfprintf-is-different-in-unreal-engine/432787/1 "2018-08-30T11:36:50Z")

</div>

I use a c++ plugin to write some text to a file and I use the vfprintf function. In a visual studio application the output would be :a|b|c but UnrealEngine writes to file a(!!T#b(!!T#c. Any idea how to solve this ?  
Thankyou

---

<div class="post-metadata">

**Author:** ![dZh0](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dZh0](https://forums.unrealengine.com/u/dZh0)\
**Post date:** [August 30, 2018, 3:22pm UTC](https://forums.unrealengine.com/t/why-vfprintf-is-different-in-unreal-engine/432787/2 "2018-08-30T15:22:09Z")

</div>

It depends on how you generate the text and it’s type but you have provided no code.

I can tell you from now that UE4 has a specific rules for [handling strings](https://docs.unrealengine.com/en-us/Programming/UnrealArchitecture/StringHandling) and files (see [FFileHelper](http://api.unrealengine.com/INT/API/Runtime/Core/Misc/FFileHelper/index.html)). Some of the C++ library functions are not supported along with some data types in order to be cross-platform. (I assume)

Check the documentation if you haven’t.

---

<div class="post-metadata">

**Author:** ![BestWarrior](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BestWarrior](https://forums.unrealengine.com/u/BestWarrior)\
**Post date:** [August 30, 2018, 8:53pm UTC](https://forums.unrealengine.com/t/why-vfprintf-is-different-in-unreal-engine/432787/3 "2018-08-30T20:53:29Z")

</div>

Hi, thankyou for answering. I used FString Fs = FString(ANSI\_TO\_TCHAR(arr));  
FString Fs = FString(UTF8\_TO\_TCHAR(arr)); but its the same output so I think there is a problem when it compiles the c code. I think its missing the \_MBCS setting which is in the default visual studio project

---

<div class="post-metadata">

**Author:** ![dZh0](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dZh0](https://forums.unrealengine.com/u/dZh0)\
**Post date:** [August 30, 2018, 9:23pm UTC](https://forums.unrealengine.com/t/why-vfprintf-is-different-in-unreal-engine/432787/4 "2018-08-30T21:23:50Z")

</div>

To directly answer the question: There is a discrepancy between the encoding of your input and your output. A string is useless without it’s encoding information. See: [Character Encoding](https://docs.unrealengine.com/en-us/Programming/UnrealArchitecture/StringHandling/CharacterEncoding).

As I implied in the comment, you should not use special characters in your text files. Always save strings in the provided types by the engine.

This is already asked in a sort but for Asian characters: [https://answers.unrealengine.com/questions/802364/view.html](https://answers.unrealengine.com/questions/802364/view.html)

The answer there is very exhaustive.

---

<div class="post-metadata">

**Author:** ![BestWarrior](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BestWarrior](https://forums.unrealengine.com/u/BestWarrior)\
**Post date:** [August 31, 2018, 1:23pm UTC](https://forums.unrealengine.com/t/why-vfprintf-is-different-in-unreal-engine/432787/5 "2018-08-31T13:23:40Z")

</div>

I wrote the text like this

`int cst\_sprintf(char \*s, const char \*fmt, …)  
{  
va\_list args;  
int rv;

```
va_start(args, fmt);
rv = vsprintf(s, fmt, args);
va_end(args);

return rv; 

```

}  
`  
I even tried to send the text through a char array and the output is the same.

---

<div class="post-metadata">

**Author:** ![BestWarrior](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BestWarrior](https://forums.unrealengine.com/u/BestWarrior)\
**Post date:** [September 4, 2018, 3:51pm UTC](https://forums.unrealengine.com/t/why-vfprintf-is-different-in-unreal-engine/432787/6 "2018-09-04T15:51:04Z")

</div>

I solved this, the encoding was not the problem. I was writing a char instead of a char \* to the file.
