3 Replies - 752 Views - Last Post: 09 June 2009 - 07:37 AM Rate Topic: -----

#1 samirpadhy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 08-June 09

Encoding_program

Post icon  Posted 08 June 2009 - 11:00 PM

Hi All,


I need a c++ program which will read a unicode format file and store in another file.Before reading the file the program should able to check whether the file is in unicode format or not.if not no need to read and store.

I never worked on unicode file ,so i do not know how to deal with it.

Please any one can help me!!!Its urgent.

Here is the code what i have tried but i dont know whether it exactly doing the job or not.As i am no clear idea about the multi-byte foramt file,so i am not getting the things exactly.
#include <iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
	wchar_t ch;
	FILE *fp;

	wchar_t *buffer = (wchar_t *)malloc(sizeof(wchar_t) * 1);
 
	fp = fopen("in.txt","rb");
 
	if( fp == NULL)
	{
		printf("Error: File cannot be access/opened\n");
		getchar();
		return 1;
	}
	else
	{
		while(fread(buffer,sizeof(wchar_t),1,fp) != 0)
		   printf("%s",buffer);
		fclose(fp);
	}
 
   system("PAUSE");
	return 0;
}



Thanx in Advance

Regards
Samir

This post has been edited by samirpadhy: 08 June 2009 - 11:31 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Encoding_program

#2 BetaWar   User is offline

  • #include "soul.h"
  • member icon

Reputation: 1695
  • View blog
  • Posts: 8,592
  • Joined: 07-September 06

Re: Encoding_program

Posted 08 June 2009 - 11:11 PM

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Post your code like this: :code:

Thanks.
Was This Post Helpful? 0
  • +
  • -

#3 castingxvoid   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 16
  • Joined: 11-December 08

Re: Encoding_program

Posted 09 June 2009 - 12:58 AM

I can't help with your problem, but might I suggest not using C-specific functions in your C++ code? It's merely bad practice, and can be unsafe. Use std::cout for output and std::cin for input. Avoid using system calls where viable alternatives exist. system("pause") can be replaced with std::cin.get().
Was This Post Helpful? 0
  • +
  • -

#4 NickDMax   User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2255
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Encoding_program

Posted 09 June 2009 - 07:37 AM

What operating system are you on? Unfortunately unicode has not turned out be as easy as I would have hoped (which is probably why it has not been as widely adopted as people would like).

It would be nice if you could just use wcout and wprintf -- but alas these seems to require some work to get working. First of all if you are on windows (I don't know about linux) the console does not support Unicode past the ASCII encoding -- i.e. it don't work with unicode. Even to get basic unicode support you have to change the font to Lucinda.

The following program does not work under windows, but if I am not mistaken (and I might be because I don't have a linux box set up at the moment) this *should* work under linux:

#define UNICODE
#include <iostream>
#include <string>
#include <wchar.h>


int main() {
	std::wstring tryme = L"This is a test";
	wchar_t greekStr[] = {0x03B1, 0x03B2, 0x03B3, 0x03B4, 0x03B5, 0x03B6, 0x0000 };
	
	std::wcout << tryme << std::endl;
	std::wcout << greekStr << std::endl;

}

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1