Unicode character in C++


Hi all,
In my application, I am reading a file and storing it in a
array of character. That is ascii format...now in certain situation I
get unicode character (or lets say junk character). I want to know
that whether it is plain ascii or Unicode...How can I \t

Posted On: Sunday 4th of November 2012 05:16:24 AM Total Views:  160
View Complete with Replies

RELATED TOPICS OF C Language PROGRAMMING LANGUAGE




Confused: while loop and characters

I'm working on a project for school that prints 4 triangles after taking a size input and character from the user. I want to make a while loop that outputs an error message if the user inputs a value less than 1 or a character when they are asked what size they want the triangles to be. I was able to set up a loop that continues to prompt the user for an integer value if they enter something less than 1(shown here); but, if a character is entered the program goes into an infinite loop. Can anyone point me in the right direction on how to fix my while loop so that it doesn't go into a infinite loop if a character is entered Code: #include #include void flush(void) { while (getchar()!='\n'); } int main(void) { int size, i, j, valid_input; char c, answer; do { Printf(enter triangle size \n); Scanf(%i ,&size); while(size
VIEWS ON THIS POST

187

Posted on:

Wednesday 17th October 2012
View Replies!

Decimal to binary conversion with character string

So I'm taking a new class that delves into assembly, but our professor is testing our C knowledge beforehand. This what he asks of us: Return the binary representation of a number x as a character string. For example : if x = 17 is passed to the function the return value should be a pointer to the string 00000000000000000000000000010001. Now, main and the function name are exactly what he has provided. So I need to basically write the function and return the string. What I was trying to do was call the function and use the value suggested (17), do the modulus to find the remainders, store that info, and then finally swap the stored values in the string so it will print in the right order (msb to lsb). My C programming class lightly covered strings and pointers so I am not great in that area, but I'm giving it my best shot. Any help or suggestions is appreciated.
VIEWS ON THIS POST

209

Posted on:

Wednesday 17th October 2012
View Replies!

Counting rows, words and characters in C

everybody! I need to write a program that reads the text file 'i5f9.dat' and calculates and displays the -number of rows, -number of words (between two words there can be more than one blank) and -the number of characters. Any suggestions Thank you!
VIEWS ON THIS POST

108

Posted on:

Wednesday 17th October 2012
View Replies!

Arrays - accented characters

It is because you are trying to put characters which aren't in the ASCII-table into a char. Encoding is a headache, look into things like UTF-8, unicode etc. if you want to know more about it. The problem is that is a multibyte char, and can't be represented by a single byte. This is actually a very interesting blog post to read about text encoding: http://www.joelonsoftware.com/articles/Unicode.html, >> Why can't I have an array like this one: It's dangerous to have character literals in in your source code that don't belong to the "basic source character set". How the compiler maps "Physical Source File Characters" to the "Execution Character Set" is implementation defined. It may depend on how the source file itself is encoded. Or it may depend on command line parameters passed to the compiler. Or it may depend on the current locale settings when the compiler is invoked. Most *nix OS's do things as UTF8, so I'll assume that your source file is encoded as UTF8 and gcc is mapping it directly to the "Execution Character Set" as UTF8 (which is common). If we look at "LATIN SMALL LETTER C WITH CEDILLA" (), its Unicode value is U+000000E7. When encoded as UTF8, it becomes "0xC3,0xA7". That's 2 bytes which gcc can't store in 'char'. >> I need to write a program that reads a string from user input, and if characters are, say, , , , , etc, they should be replaced with c, C, a (just as an example). Why do you need to do this This is typically the wrong approach to take, unless you have special circumstances that require it. gg, [QUOTE=Codeplug;1066025]>> Why can't I have an array like this one: It's dangerous to have character literals in in your source code that don't belong to the "basic source character set". How the compiler maps "Physical Source File Characters" to the "Execution Character Set" is implementation defined. It may depend on how the source file itself is encoded. Or it may depend on command line parameters passed to the compiler. Or it may depend on the current locale settings when the compiler is invoked. Most *nix OS's do things as UTF8, so I'll assume that your source file is encoded as UTF8 and gcc is mapping it directly to the "Execution Character Set" as UTF8 (which is common). If we look at "LATIN SMALL LETTER C WITH CEDILLA" (), its Unicode value is U+000000E7. When encoded as UTF8, it becomes "0xC3,0xA7". That's 2 bytes which gcc can't store in 'char'. [QUOTE] Yes, the source file is encoded as UTF8. I use vim, and it is set to write files in utf8. Originally Posted by Codeplug >> I need to write a program that reads a string from user input, and if characters are, say, , , , , etc, they should be replaced with c, C, a (just as an example). Why do you need to do this This is typically the wrong approach to take, unless you have special circumstances that require it. gg The teacher asked the students to do it. No one was able do achieve it up to the present moment. It has no special purpose other than being able to do it, I guess. It is an exercise. I didn't mention that before because I didn't want the code. I just wanted some tips, but I spent all morning reading about this, and I'm feeling stymied by now.
VIEWS ON THIS POST

104

Posted on:

Wednesday 17th October 2012
View Replies!

How to put invisible characters

! im making my scissor,paper and rock game on c++ program . I need to replace scanf to enter a invisible characters when other user is typing , can you say what code it is thanks my code: Code: #include #include main() { int a,b; clrscr(); printf("NOTE:s(scissor),p(paper),r(rock)"); printf("\nPLAYER 1 BEGINS:"); scanf("%s",&a); printf("\nPLAYER 2 turns:"); scanf("%s",&b); if (a=='s' && b=='p') printf("P1 WINS!"); else if (a=='p' && b=='r') printf("P1 WINS!"); else if (a=='r' && b=='s') printf("P1 WINS!"); else if (a=='p' && b=='s') printf("P2 WINS!"); else if (a=='s' && b=='r') printf("P2 WINS!"); else if (a=='s' && b=='r') printf("P2 WINS!"); else if (a=='s' && b=='s') printf("DRAW!"); else if (a=='p' && b=='p') printf("DRAW!"); else if (a=='r' && b=='r') printf("DRAW!"); else printf("YOU'RE OUT OF WORLD!"); } getch(); }
VIEWS ON THIS POST

136

Posted on:

Thursday 18th October 2012
View Replies!

How to loop a single character?

, I have a little over 3 days of C experience so bear with me! I understand how to print 1-100: Code: for (i = 1; i < 100; i++) printf("%d\n", i); And also A-Z: Code: for (ch = 'A'; ch
VIEWS ON THIS POST

167

Posted on:

Thursday 18th October 2012
View Replies!

trouble counting characters.

I am having trouble writing a program that counts the amount of th's in an inputted text. I think I have the right code, but I keep getting an error saying that left operand must be an l-value. This would be in the else-if block (thisChar = 'h'). here is my code. Code: int numThs = 0; char thisChar, lastChar = ' '; while (scanf("%c", &thisChar) != EOF){ if (scanf("%c", &thisChar) == 1){ if (thisChar = 't') lastChar = thisChar; else if (thisChar = 'h' && lastChar = 't') numThs++; } } printf("There were %d th's.\n", numThs);
VIEWS ON THIS POST

170

Posted on:

Thursday 18th October 2012
View Replies!

character strings

hey i kinda need help with this program i wrote today. i am trying to get the names of 8 game characters off the user, then i ask what position they came in using switch statement to assign a certain amount of points to whatever position they came in and finally print to the screen their total points after 4 games. note: the last line only includes one game character because i didnt want to bother writing 8 print statements until i was sure the program would work. the only thing wrong with the program is character string declaration. im not sure how to declare a,b,c,d,e,f,g,h as char strings . PLEASE HELP! AND ALSO IF YOU HAVE ANY TIPS OR TRICKS TO SHORTEN THE PROGRAM THEN I WILL HONOURABLY ACCEPT. THANKS Code: #include Code: int main() { char stringa[20], stringb[20], stringc[20], stringd[20], stringe[20], stringf[20], stringg[20], stringh[20]; int place,i; printf("Enter the ctr characters\n"); scanf("%s%s%s%s%s%s%s%s",&a,&b,&c,&d,&e,&f,&g,&h); for(i=1;i
VIEWS ON THIS POST

112

Posted on:

Saturday 20th October 2012
View Replies!

Transferring non-repeated characters to another string

Code: #include#include #define size 50 void count(char s[size]); main(){ char str[size]; int num = 7; printf("Enter a string: "); scanf("%s", str); count(str); } void count(char s[size]){ char str[size]; int str_cnt[size] = {}, i, j, str_s = strlen(s); for(i = 0; i < str_s; i++){ if(strlen(str) == 0){ str[0] = s[i]; str_cnt[0]++; str[1] = '\0'; } else{ //check if character already exists for(j = 0; j < strlen(str); j++){ //if it exists then increment //printf("%c, %c\n", s[i], str[j]); if(s[i] == str[j]){ str_cnt[j]++; break; } } //if not, then add to the character array then increment if(j == strlen(str)){ str_cnt[j]++; str[j] = s[i]; str[j+1] = '\0'; } } } for(i = 0; i < str[i] != '\0'; i++){ printf("%c - %d\n", str[i], str_cnt[i]); } } This program will count how many times a character was used in a word. Now, I want to modify it so that it will remove letters that was used more than 1. Since I do not know how to remove a character from a string, my idea is to transfer the letters that were only used once to another string. Example: Enter string: google g-2 o-2 l-1 e-1 Output: le Is this possible Or is removing(if such function exists) a character much easier
VIEWS ON THIS POST

111

Posted on:

Saturday 20th October 2012
View Replies!

how to input a string of character?

-I know how to scanf a character but dont know how to scanf a string. This is correct scantf("%f",lop); -How to define the variable to save the string in string "lop";
VIEWS ON THIS POST

137

Posted on:

Saturday 20th October 2012
View Replies!

Printing Unicode characters

. I've been searching for this, but I'm having some difficulties on finding it: how do I display Unicode characters in C in the Windows operating system For example, I wanted to print the superscript 4, whose code is 2074, as is shown in http://www.unicode.org/charts/PDF/U2070.pdf.
VIEWS ON THIS POST

121

Posted on:

Sunday 21st October 2012
View Replies!

Array of character pointers

Could anyone check out this code and give me a hint of what I'm doing wrong I'm trying to make a code that has the user enter a number 1-7, and it displays a day corresponding to that number. For example, 1 = sunday, 2 = monday, etc. Strings are kind of confusing to me right now, so I'm not sure if I'm really far off or close. If anyone has any recommendations on a good string tutorial that would be nice When I run this, it asks the user for a number, but regardless of what number I put in, even if it's between 1 and 7, it displays the 'else' statement.
VIEWS ON THIS POST

116

Posted on:

Monday 22nd October 2012
View Replies!

enter a decimal number and give me a ASCII character upto 127?

Code: #include #include void main() { int x; printf("Enter a decimal number\n",x); printf("The character is %c\n",x); getch (); } whats wrong with it.it does not give any ascii code.please tell me simple program.
VIEWS ON THIS POST

133

Posted on:

Monday 22nd October 2012
View Replies!

Need help with simple program that uses printf, scanf, and characters

. I am writing a program that prompts the user to enter 5 characters and then prints them in a wedge shaped like ">". This is my code: Code: #include int main() { char first, second, third, fourth, fifth; printf("First character: "); scanf("%c", &first); printf("Second character: "); scanf("%c", &second); printf("Third character: "); scanf("%c", &third); printf("Fourth character: "); scanf("%c", &fourth); printf("Fifth character: "); scanf("%c", &fifth); printf("%c", first); printf("%3c", second); printf("%5c", third); printf("%3c", fourth); printf("%c\n", fifth); return 0; } When I compile and run the program, however, after inputting the first character and pressing enter, "Second character: Third character: " prints all at once, and then "Fourth character: Fifth character: " prints all at once, as well. Can someone help me understand why it is not going along one command at a time
VIEWS ON THIS POST

229

Posted on:

Tuesday 23rd October 2012
View Replies!

How to convert char string of Hex characters to unsigned char string of binary data

I am trying to convert a hexadecimal character array to a binary string (unsigned char) that I can use in crypto functions using Cryptlib or OpenSSL. Basically I have a Hex representation of a key like (02726d40f378e716981c4321d60ba3a3) which as a character string is 32 characters but as a binary string should be 16 bytes. The character string is being read in from a file, how can I convert it to its binary representation as an unsigned char array
VIEWS ON THIS POST

170

Posted on:

Tuesday 23rd October 2012
View Replies!

Difference between character pointer

Hi all, What is the difference between char *a and char * a Where char * a can be used Thank you in advance., No difference in there declaration. Just one of C's many faults.
VIEWS ON THIS POST

157

Posted on:

Tuesday 23rd October 2012
View Replies!

How to assign an ASCII character via inline assembly code

I am having difficulties executing a short __asm__() exercise: Write assembly code to store char 'A' into bufone[0]. I would think it should look like this: Code: #include char* bufone; int main(int argc, char* argv[]) { __asm__("movl $0x41, bufone\n"); printf("\n%s\n", bufone[0]); return 0; } However, I keep getting Segmentation Fault errors. What am I missing
VIEWS ON THIS POST

125

Posted on:

Tuesday 23rd October 2012
View Replies!

Multi-character constants

After reading through some (open) Intel (CPU detection) C++ source (http://www.intel.com/cd/ids/develope...eng/276611.htm) I stumbled upon a sketchy use of multibyte characters - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 260: unsigned int VendorID[3] = {0, 0, 0}; try // If CPUID instruction is supported { ... } catch (...) { ... } return ( (VendorID[0] == 'uneG') && (VendorID[1] == 'Ieni') && (VendorID[2] == 'letn') ); - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - This seems to work, gcc 4.2 emits a warning: "warning: multi-character character constant" and Visual C++ 9 says nothing at all. Whats the matter w/multibyte characters now I didn't use them and would be glad to learn if they are widely implemented and part of the standard soon/now gcc tells us: (http://gcc.gnu.org/onlinedocs/gcc/Ch...mentation.html) ... [Characters] ... The value of a wide character constant containing more than one multibyte character, or containing a multibyte character or escape sequence not represented in the extended execution character set (C90 6.1.3.4, C99 6.4.4.4). ...
VIEWS ON THIS POST

172

Posted on:

Sunday 4th November 2012
View Replies!

printability of extended ASCII characters

How do you discover if a character including extended ASCII characters are printable By extended ASCII I mean codes above 7Fx0, for example '', 84x0. The following dubious code works on Windows, ( MSVC and g+ + ) but not on Linux. bool is_printable( char c ) { const wint_t unsigned_c( ( c >= 0 ) c : 256 + c ); return iswprint( unsigned_c ) != 0; } I am not actually sure what printable means in this context. What I actually want to know is whether I can write such a character to file and expect it to be redisplayed correctly in a text editor. Extended ASCII characters are displayed in notepad and gedit, but not in a terminal.
VIEWS ON THIS POST

215

Posted on:

Sunday 4th November 2012
View Replies!

list all characters available

Hi I'm trying to write an app and don't know how to start. I'll have a selector with a list of true type fonts. Each font will represent a different set of chars. Example *arial-font *arabic-font *russian-font *cyrillic-font When the user select one of them, I should list all chars available in the font. With ansi characterset it's easy, just loop from 0-255 and print the char representation of an integer value, but I don't know how to achieve this. Any idea
VIEWS ON THIS POST

233

Posted on:

Sunday 4th November 2012
View Replies!