www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/07/29/06:09:32

Message-ID: <006301c1181e$0ed4d800$0c64a8c0@tpc2>
From: thorsten-erdmann AT t-online DOT de (Thorsten Erdmann)
To: <djgpp AT delorie DOT com>
Subject: Problems with strupr etc.
Date: Sun, 29 Jul 2001 13:03:11 +0200
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 5.00.2615.200
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200
X-Sender: 520027981173-0001 AT t-dialin DOT net
Reply-To: djgpp AT delorie DOT com

Hi,

I have some problems with the strupr and strlower functions and the ones
which are based upon, like stricmp.
If strupr finds a non ASCI character like 128 or higher it breaks at that
point leaving the string incomplete or it places illegal characters there.
The right behaviour would be to leave the character as it is. Maybe it is
something with signed or unsigned characters, since it only happens with
characters higher or equal than 128.

I looked at the sources and found that strupr calls toupper, so I tried
that - with the same result. So I copied the source of toupper in my own C
souzrce to debug it - and the error is gone. Mysterious ! What can be the
mistake. Is there somethink run wrong when making libc? I have writte a
small test application to demonstrate that. Maybe you can figure something
out.

BTW. How can I rebuilt libc. The makefile only gives error messages.

#include <string.h>
// if you skip this include and insert a copy of the tolower function here
all works fine

int main()
{
  unsigned char s1[256],s2[256];
  int  i;

  for (i=32;i<256-32;i++) s1[i-32]=i;
  s1[i]=0;
  puts("strlwr:");
  puts(s1);
  strcpy(s2,s1);
  strlwr(s2);
  puts(s2);
  puts("");

  puts("strupr:");
  puts(s1);
  strcpy(s2,s1);
  strupr(s2);
  puts(s2);
  puts("");

  for (i=32;i<256;i++)
  {
    printf("%i:%i (%c:%c)\n",i,tolower(i),i,tolower(i));
    getch();
  }
  return 0;
}



- Raw text -


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