473,546 Members | 2,644 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

fprintf() not saving a file in utf8

110 New Member
fprintf() is saving a file in utf8 but Bom for utf8 is missing..
Can we save a file with utf8 BOM? for eg.
I want to save a file with BOM .. EF BB BF in the beginning..
is it possible to do that in C++?

Thnx in advance..
Xoinki
Apr 26 '07 #1
1 6032
xoinki
110 New Member
hi,
I finally found the answer...

const unsigned char UNICODE_BOM[3] = {unsigned char(0xEF), unsigned char(0xBB), unsigned char(0xBF)};

int _tmain(int argc, _TCHAR* argv[])
{
FILE *fp = fopen("C:/wi32.txt", "w+");
int a = sizeof(UNICODE_ BOM);
fwrite(static_c ast<void *>((void *)(UNICODE_BOM) ), a, 3,fp);
..........
.......
......
}
this writes the required BOM
Apr 26 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
5894
by: Börni | last post by:
Hi, The question might sound (and probably is;-) stupid, but why doesnt the follwing code work?? Is there something i dont see? $doc = new DOMDocument('1.0', 'iso-8859-1'); $doc->formatOutput = true; $root = $doc->createElement('root'); $root = $doc->appendChild($root);
3
7738
by: hunterb | last post by:
I have a file which has no BOM and contains mostly single byte chars. There are numerous double byte chars (Japanese) which appear throughout. I need to take the resulting Unicode and store it in a DB and display it onscreen. No matter which way I open the file, convert it to Unicode/leave it as is or what ever, I see all single bytes ok, but...
6
3481
by: hpy_awad | last post by:
I am writing stings ((*cust).name),((*cust).address)to a file using fgets but rabish is being wrote to that file ? Look to my source please and help me finding the reason why this rabish is being written. /* Book name : File name : E:\programs\cpp\iti01\ch10\ex09_5p1.cpp Program discription: Adding name,Address to...
8
1979
by: Smegly | last post by:
Hi, I'm confused about a situation i have .. fprintf works in one function, but not in the other . . This is my part of my code for the two functions .. void customer(FILE *fin, FILE *fout, int msqid, message_buf sbuf, size_t
17
2779
by: G Patel | last post by:
E. Robert Tisdale wrote: > > int main(int argc, char* argv) { > quad_t m = {0, 1, 2, 3}; > int r; > fprintf(stdout, "m = ("); > for (size_t j = 0; j < 4; ++j) Why did you declare j as type size_t ?
4
4943
by: baumann | last post by:
hi all, i want to use the fprintf to make log. if defined LOG_TO_FILE, it is easy to use fprintf to write the log file. if not defined LOG_TO_FILE, i want to simply write to error std console.
2
1809
by: perspolis | last post by:
Hi all I want to save my c# files with unicode encoding. I have some choices in encoding like: 1-Unicode-CodePage1200 2-Unicode(UTF8 with singnaure)-CodePage 65001 3-Unicode(UTF8 without singnaure)-CodePage 65001 which encoding is better to use unicode?/? thanks in advance
1
2040
by: xoinki | last post by:
hi all, I have some data.. and I want to save it into a file.. the data may be encoded in any format.. for simplicity let us consider, only 2 formats.. either Utf8 or latin1.. if i save latin1 data it will be saved as ANSI.. if i save utf8 it will be saved as Unicode. Is there any way to detect encoding format of the file? Or, Forcibly...
16
6665
by: Prayag Narula | last post by:
Hi, I want to redefine fprintf for debugging purposes. That is I want that all the output that is going to the stdout should be logged in a file. I tried something like #define fprintf (x,y,z) my_fprintf(x,y,z)
0
7504
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7435
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7694
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7792
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6026
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5360
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3491
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1921
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.