Change Case
LCase, UCase and MCase string helpers built on strlwr/strupr with a rotating buffer of results.
A set of Visual-Basic-style string functions for C: LCase and UCase wrap strlwr/strupr, while MCase capitalizes the first letter and lowercases the rest by composing them with Left and Mid. Each function returns a pointer into a rotating bank of 64 static buffers, so up to 64 results stay live at once - handy when you are building display strings from pieces without managing every malloc yourself. Use it as a quick reference for case conversion and substring helpers in Win32 console code.
#include <windows.h>
#include <stdio.h>
static int StrCnt;
static char StrFunction [64][257];
extern char *LCase (char *);
extern char *UCase (char *);
extern char *Mid (char *, int, int);
extern char *Left (char *, int);
extern char *MCase (char *);
int main(int argc, char *argv[])
{
printf("MCase %s\n",MCase("tRaNsLaToR"));
printf("LCase %s\n",LCase("tRaNsLaToR"));
printf("UCase %s\n",UCase("tRaNsLaToR"));
return 0;
}
extern char *UCase (char *S)
{
static char Tmp [257];
if(++StrCnt==64) StrCnt = 0;
sprintf(Tmp,"%s",S);
{sprintf (StrFunction[StrCnt],"%s",strupr(Tmp));}
return StrFunction[StrCnt];
}
extern char *LCase (char *S)
{
static char Tmp [257];
if(++StrCnt==64) StrCnt = 0;
sprintf(Tmp,"%s",S);
{sprintf (StrFunction[StrCnt],"%s",strlwr(Tmp));}
return StrFunction[StrCnt];
}
extern char *MCase (char *A)
{
static char T[257];
if (++StrCnt==64) StrCnt = 0;
sprintf(T,"%s%s",UCase(Left(A,1)),LCase(Mid(A,2,256)));
sprintf(StrFunction[StrCnt],"%s",T);
return StrFunction[StrCnt];
}
extern char *Mid (char *S, int start, int length)
{
if(++StrCnt==64) StrCnt = 0;
if (start > strlen(S)) { StrFunction[StrCnt][0]='\0'; }
else
{strncpy (StrFunction[StrCnt], &S [start-1], length);}
StrFunction[StrCnt][length]='\0';
return StrFunction[StrCnt];
}
extern char *Left (char *S, int length)
{
if(++StrCnt==64) StrCnt = 0;
strncpy (StrFunction[StrCnt], &S[0], length);
return StrFunction[StrCnt];
}