04-09-2013, 06:02 AM | #21 | ||
Join Date: Mar 2006
Location: ,
Posts: 4,613
|
wchar_t is defined even in C89, but you have to include <stdlib.h> or <stddef.h>.
http://en.wikipedia.org/wiki/Wide_character#C.2FC.2B.2B Quote:
Why a teacher would make someone who's starting to program deal with this, is beyond me...
__________________
Life starts every day anew. Prospects not so good... Last edited by Japo; 04-09-2013 at 06:20 AM. |
||
|
|
05-09-2013, 08:02 PM | #22 | ||
Join Date: May 2010
Location: Brazil
Posts: 91
|
You are right, I stand corrected.
|
||
|
|
05-09-2013, 09:29 PM | #23 | ||
Join Date: Mar 2006
Location: ,
Posts: 4,613
|
Yep I had no idea myself, I just researched it on the go, so I was learning too. I've tried enabling the "compile as C" (as opposed to C++) in Visual Studio and this code works, I think it should be portable to any Unicode-enabled platform:
Code:
#include <stdio.h> #include <stddef.h> #include <io.h> #include <fcntl.h> int main(void) { _setmode(_fileno(stdout), _O_U16TEXT); wprintf(L"Hell\u00f8 wørld!\n"); return 0; }
__________________
Life starts every day anew. Prospects not so good... |
||
|
|
05-09-2013, 10:14 PM | #24 | ||
Join Date: May 2010
Location: Brazil
Posts: 91
|
Well, we are always learning. I researched a bit more and it seems wchar_t has no defined size, and could be only 8 bits wide, so it doesn't look portable.
|
||
|
|
05-09-2013, 10:35 PM | #25 | ||
Join Date: Mar 2006
Location: ,
Posts: 4,613
|
As portable as it gets in this case, I think. In practice I think in most (all non embedded) implementations wchar_t will be wider than 8-bit, but the bigger risk is no Unicode support (probably compile time error that _O_U16TEXT isn't defined, like I get in TC++ 1.01). That's why I like C# or D in which regular strings are always already Unicode. Also standards are as useful as they are but not more (ask SQL...)
__________________
Life starts every day anew. Prospects not so good... Last edited by Japo; 05-09-2013 at 11:04 PM. |
||
|
|
02-07-2014, 08:45 PM | #26 | ||
Join Date: Mar 2006
Location: Krakeroy, Norway
Posts: 3,014
|
I need to ask again:
This time, I'm trying to write a code (C) that will generate prime numbers. Thing is, all the sample code I've seen checks each number up against all other, lower, natural numbers but the point is, that is not necessary and in fact will save me a LOT of time as the primes get larger if I only check up against the lower primes I generate. The idea is to write the primes to a txt file (since 10,000,000,000 primes can take up a lot of memory), and read this list to check the candidate number. Problem is: I use fscanf and it really isn't playing ball. Either it reads the entire list as one number or it stops reading as soon as it hits a space or new line. Is there a neat way of reading each number in the list while allowing for space and new line? Also, is there a way to jump straight to the last number in the list instead of having to go through the entire nightmare everytime I want to resume the job? The idea here is, when I want to resume the job after a break, I want the program to pick the last prime found + 1 as the new candidate.
__________________
Je Suis Charlie Last edited by Mighty Midget; 02-07-2014 at 08:49 PM. |
||
|
|
05-07-2014, 01:04 AM | #27 | ||
Join Date: Mar 2006
Location: ,
Posts: 4,613
|
The problem is that if you don't want to read the whole file in one go, you need the FILE pointer to be moved from the start of the file to where you finished the last read.
Use fread(), it moves the pointer automatically, and allows you to read any number of numbers in each call. I think binary mode will be better than text. http://msdn.microsoft.com/en-us/library/kt0etdcs.aspx Quote:
__________________
Life starts every day anew. Prospects not so good... |
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
EoF Corner | Eagle of Fire | Offers | 6 | 03-02-2010 05:01 PM |
The end of the file corner | Eagle of Fire | Music, Art, Movies | 8 | 08-12-2009 12:09 AM |
Spoonman's Art Corner | Spoonman | Music, Art, Movies | 122 | 15-01-2009 09:35 PM |
Spoonman's Music Corner | Spoonman | Music, Art, Movies | 3 | 25-06-2005 05:18 PM |
Thread Tools | |
Display Modes | |
|
|
||
  |