🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: memcpy et char

#15494
From: Marc Boyer
Date: Fri, 23 Sep 2005 14:02
63 lines
2704 bytes
Le 23-09-2005, Alain CROS <Personne@ICI> a �crit�:
> J'ai corrig� un petit bug dans ma fonction et supprim� une variable.
>
> #include <string.h>

  Allez, je suis pas le meilleur � ce jeu l�, mais je tente.

> int convstrnum(int taille, char *c)

bool convstrnum(size_t 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;

  C'est quoi 'i' et 'j' ?

>     char ch[taille + 1];

  Souvent une mauvaise id�e: si on a pas la m�moire
pour allouer taille+1, ben, �a va faire boum, et on
a pas moyen de le savoir.

>     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;

  Heuh ? En d�cript�, �a donne quoi ?

>                     break;
>                 default:
>                     j = -1;
>             }
>         if(j == -1)
>             break;
>         *pch++;
>         i++;
>     }
>     if(j != -1)
>         memcpy(c, ch, taille);
>     return(j);
> }


-- 
� v�lo, prendre une rue � contre-sens est moins dangeureux
que prendre un boulevard dans le sens l�gal. � qui la faute ?
Technical Details
Message-ID: <slrndj82rt.8m8.Marc.Boyer@localhost.localdomain>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!134.158.69.22.MISMATCH!in2p3.fr!univ-lyon1.fr!jussieu.fr!crihan.fr!univ-lille1.fr!news.cict.fr!not-for-mail
References: <4333e995$0$17469$626a14ce@news.free.fr> <4333f1ef$0$5425$626a14ce@news.free.fr> <43340870$0$18817$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!134.158.69.22.MISMATCH!in2p3.fr!univ-lyon1.fr!jussieu.fr!crihan.fr!univ-lille1.fr!news.cict.fr!not-for-mail
From: Marc Boyer <Marc.Boyer@enseeiht.yahoo.fr.invalid>
Newsgroups: fr.comp.lang.c
Subject: Re: memcpy et char
Date: Fri, 23 Sep 2005 14:02:08 +0000 (UTC)
Organization: CICT
Lines: 63
Message-ID: <slrndj82rt.8m8.Marc.Boyer@localhost.localdomain>
References: <4333e995$0$17469$626a14ce@news.free.fr> <4333f1ef$0$5425$626a14ce@news.free.fr> <43340870$0$18817$626a14ce@news.free.fr>
Reply-To: Marc.Boyer@enseeiht.yahoo.fr (del yahoo)
NNTP-Posting-Host: ubu.enseeiht.fr
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: news.cict.fr 1127484128 8609 147.127.19.155 (23 Sep 2005 14:02:08 GMT)
X-Complaints-To: usenet@news.cict.fr
NNTP-Posting-Date: Fri, 23 Sep 2005 14:02:08 +0000 (UTC)
User-Agent: slrn/0.9.8.1 (Debian)