Article View: fr.comp.lang.c
Article #15491Re: memcpy et char
From: Alain CROS
Date: Fri, 23 Sep 2005 13:51
Date: Fri, 23 Sep 2005 13:51
59 lines
2507 bytes
2507 bytes
Bonjour.
"Stephane Legras-Decussy" <admin@dtc.fr> a �crit dans le message de news: 4333f1ef$0$5425$626a14ce@news.free.fr...
| > Est ce n�cessaire d'�crire
| > memcpy(ch, c, sizeof(char) * taille);
| > ou bien je peux me contenter d'�crire
| > memcpy(ch, c, taille);
|
| sizeof(char) vaut obligatoirement 1...
|
| donc la 2eme propositions suffit...
Si je comprends bien, que le char soit sur 7, 8, 9, ... bits, il correspond toujours a l'unit� de base du syst�me qui sera utilis�
par memcpy et sizeof(char) sera toujours �gale � 1.
Merci.
Alain CROS
J'ai corrig� un petit bug dans ma fonction et supprim� une variable.
#include <string.h>
int convstrnum(int taille, char *c)
/* Remplace, dans une chaine de caract�res repr�sentant un chiffre,
la virgule par un point.
Retourne :
la position de ce point dans la chaine (base 1).
0 si pas de point.
-1 si pas un chiffre (la chaine reste inchang�e).
*/
{
int i = 1, j = 0;
char ch[taille + 1];
char *pch = ch;
memcpy(ch, c, taille);
ch[taille] = '\0';
while(*pch != '\0')
{
if((*pch < '0') || (*pch > '9'))
switch(*pch)
{
case ',':
*pch = '.';
case '.':
j = (j == 0) ? i : -1;
break;
default:
j = -1;
}
if(j == -1)
break;
*pch++;
i++;
}
if(j != -1)
memcpy(c, ch, taille);
return(j);
}
Technical Details
Message-ID:
<43340870$0$18817$626a14ce@news.free.fr>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!infeed-3.proxad.net!news18-e.free.fr!not-for-mailReferences:
<4333e995$0$17469$626a14ce@news.free.fr> <4333f1ef$0$5425$626a14ce@news.free.fr>Show Full Headers
Complete Article Headers
X-Google-Thread: f9822,366ad66ae342f8da X-Google-Attributes: gidf9822,public X-Google-Language: FRENCH,ASCII Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!infeed-3.proxad.net!news18-e.free.fr!not-for-mail From: "Alain CROS" <Personne@ICI> Newsgroups: fr.comp.lang.c References: <4333e995$0$17469$626a14ce@news.free.fr> <4333f1ef$0$5425$626a14ce@news.free.fr> Subject: Re: memcpy et char Date: Fri, 23 Sep 2005 15:51:52 +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: 61 Message-ID: <43340870$0$18817$626a14ce@news.free.fr> Organization: Guest of ProXad - France NNTP-Posting-Date: 23 Sep 2005 15:51:45 MEST NNTP-Posting-Host: 62.147.11.72 X-Trace: 1127483505 news18-e.free.fr 18817 62.147.11.72:1040 X-Complaints-To: abuse@proxad.net