delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/02/28/08:27:35

From: "Rafael García" <rafael AT geninfor DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: atoi() with 8 bit chars
Date: Wed, 28 Feb 2001 14:09:30 +0100
Organization: BT Tel. Netnews service (readers)
Lines: 25
Message-ID: <3a9cf8f1$1@filemon.telecable.es>
NNTP-Posting-Host: filemon.telecable.es
Mime-Version: 1.0
X-Trace: titan.bt.es 983365786 23179 212.89.0.4 (28 Feb 2001 13:09:46 GMT)
X-Complaints-To: abuse AT bt DOT es
NNTP-Posting-Date: 28 Feb 2001 13:09:46 GMT
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2615.200
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200
X-Original-NNTP-Posting-Host: cm05118.telecable.es
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hello all. I have found a bug in one of my functions due to an extrange
behaviour of atoi() with bad data introduced by a user in a date. If you
give 8-bit chars to atoi, it does not return cero. Does anybody know why?

#include <stdio.h>
#include <stdlib.h>

int main() {
   int n;
   char s1[]="?";
   char s2[]="?0";

   for (n=0;n<=255;n++) {
      printf("%d:\t",n);
      s1[0]=n;
      printf("atoi(\"%s\")=%d\t",s1,atoi(s1));
      s2[0]=n;
      printf("atoi(\"%s\")=%d\n",s2,atoi(s2));
      }
   return 0;
   }




- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019