🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: fr.comp.lang.c
Article #15664

Re: Conversion int --> char

#15664
From: Alain CROS
Date: Thu, 15 Sep 2005 16:06
45 lines
2206 bytes
Bonjour.

"Emmanuel Delahaye" <emdel@YOURBRAnoos.fr> a �crit dans le message de news: mn.746d7d599f15346c.15512@YOURBRAnoos.fr...

Merci pour ces explications.
J'ai fait un petit test en rempla�ant getchar par la lecture d'un fichier texte que j'avais pr�alablement enregistr� au format
UNICODE.
Comme je l'avais pr�vu, �a ne fonctionne pas.
Si je change le type du tableau de char en int, �a compile avec 1 warning sur la ligne Printf (int au lieu de char) mais rien ne
s'affiche car le premier char = 0.

Le type char ne semble pas adapt� a cette situation donc comment faire pour stocker une cha�ne de caract�res UNICODE et pouvoir
l'afficher � l'�cran.

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","r");
 if(!f)
  exit(1);
 while ((c = getc (f)) != '\n'
  && c != EOF
  && j < sizeof string - 1)
 {
  string[j] = c;
  assert (string[sizeof string - 1] == 0);
  j++;
 }
 string[j] ='\0';
 assert (string[sizeof string - 1] == 0);
 printf ("\n%s\nj = %u\n", string, j);
 fclose(f);
 return 0;
}
Technical Details
Message-ID: <43299c1a$0$29448$636a15ce@news.free.fr>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!fr.ip.ndsoftware.net!proxad.net!infeed-2.proxad.net!news15-e.free.fr!not-for-mail
References: <43285040$0$14548$636a55ce@news.free.fr> <mn.746d7d599f15346c.15512@YOURBRAnoos.fr>

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!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!fr.ip.ndsoftware.net!proxad.net!infeed-2.proxad.net!news15-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>
Subject: Re: Conversion int --> char
Date: Thu, 15 Sep 2005 18:06:22 +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: 47
Message-ID: <43299c1a$0$29448$636a15ce@news.free.fr>
Organization: Guest of ProXad - France
NNTP-Posting-Date: 15 Sep 2005 18:06:50 MEST
NNTP-Posting-Host: 62.147.58.133
X-Trace: 1126800410 news15-e.free.fr 29448 62.147.58.133:1028
X-Complaints-To: abuse@proxad.net