Article View: fr.comp.lang.c
Article #15425Re: getchar() sur source Unicode [Fut: Conversion int --> char]
From: Alain CROS
Date: Mon, 19 Sep 2005 13:57
Date: Mon, 19 Sep 2005 13:57
56 lines
2619 bytes
2619 bytes
Bonjour.
| Je suppose que vous �tes sous Windows (le .txt) et que � UNICODE � pour vous
| signifie en fait UTF-16.
Oui, je suis sur Windows 98, donc pas d'UNICODE. J'ai enregistr� mon fichier sur un autre poste en UNICODE pour tester, donc
UTF-16, je ne sais pas (mon poste ne me propose que UTF-7 et UTF-8).
|
| On peut aussi faire les manipulations � � la mimine � avec getc(), en lisant
| les char par couple ; mais l� je pose une question : que voulez-vous sortir
| ? des caract�res normaux, ou UNICODE ?
|
Le but serait d'afficher � l'�cran (caract�res normaux) le texte contenu dans le fichier.
Donc je lis chaque char avec getc(), je ne prend pas en compte les 0.
Il semblerait que les 2 premiers char du fichier correspondent � un code qui doit vouloir dire texte en UNICODE.
Ces 2 char sont -1 et -2 affich� par printf avec %u.
Le premier -1 correspond � EOF mais je ne comprend pas pourquoi ma boucle de lecture ne s'arr�te pas puisqu'elle teste EOF.
Merci.
Alain CROS
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
int main (void)
{
char string[10] = "";
unsigned int j = 0;
int c;
FILE *f;
f = fopen("Wide.txt","rb");
if(!f)
exit(1);
while ((c = getc (f)) != '\n'
&& c != EOF
&& j < sizeof string - 1)
{
if(c != '\0')
{
string[j] = c;
assert (string[sizeof string - 1] == 0);
j++;
}
}
fclose(f);
string[j] ='\0';
assert (string[sizeof string - 1] == 0);
printf ("\n%s\nj = %u\n", string, j);
printf("%u\n%u\n%u\n", string[0] , string[1], EOF);
return 0;
}
Technical Details
Message-ID:
<432ec68a$0$3758$626a14ce@news.free.fr>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!infeed-4.proxad.net!news18-e.free.fr!not-for-mailReferences:
<43285040$0$14548$636a55ce@news.free.fr> <mn.746d7d599f15346c.15512@YOURBRAnoos.fr> <43299c1a$0$29448$636a15ce@news.free.fr> <dgc9t3$5hd$1@shakotay.alphanet.ch>Show Full Headers
Complete Article Headers
X-Google-Thread: f9822,2c3d52d9f1b4dc77 X-Google-Attributes: gidf9822,public X-Google-Language: FRENCH,ASCII Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!infeed-4.proxad.net!news18-e.free.fr!not-for-mail From: "Alain CROS" <Personne@ICI> Newsgroups: fr.comp.lang.c References: <43285040$0$14548$636a55ce@news.free.fr> <mn.746d7d599f15346c.15512@YOURBRAnoos.fr> <43299c1a$0$29448$636a15ce@news.free.fr> <dgc9t3$5hd$1@shakotay.alphanet.ch> Subject: Re: getchar() sur source Unicode [Fut: Conversion int --> char] Date: Mon, 19 Sep 2005 15:57:13 +0200 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Lines: 58 Message-ID: <432ec68a$0$3758$626a14ce@news.free.fr> Organization: Guest of ProXad - France NNTP-Posting-Date: 19 Sep 2005 16:09:14 MEST NNTP-Posting-Host: 62.147.58.208 X-Trace: 1127138954 news18-e.free.fr 3758 62.147.58.208:1068 X-Complaints-To: abuse@proxad.net