Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Homework

Name: Anonymous 2009-07-13 13:47

Write a routine which makes string uppercase or lowercase in language of your choice in least possible execution time.

Name: Anonymous 2009-07-13 14:03

#include <ctype.h>
void uppercase (char *s) {
    while (*s) *s = toupper (*s++);
}

Name: FrozenVoid 2009-07-13 14:25

#include <stdio.h>
#include <stdlib.h>
inline void lcase(char *str){while(*str){*str++|=32;}}
inline void ucase(char *str){while(*str){*str++&=223;}}
void main(int argc,char **argv){
if(argc<2){printf("No arguments");exit(1);}
char* argstr=argv[1];
ucase(argstr);printf("Uppercase:%s\n",argstr);
lcase(argstr);printf("Lowercase:%s\n",argstr);}




____________________________________________
http://xs135.xs.to/xs135/09042/av922.jpg
Men who long for freedom begin the attempt to obtain it by entreating their masters to be kind enough to protect them by modifying the laws which these masters themselves have created!

Name: " 2009-07-13 14:34

void mkUpper (char* s)
{
    while (*s)
    {
        if ((*s >= 97) && (*s <= 122))
            *s &= ~(32);
    }
}



void mkLower (char* s)
{
    while (*s)
    {
        if ((*s >= 65) && (*s <= 90))
            *s |= 32;
    }
}

Name: Anonymous 2009-07-13 14:34

>>3
void upper(char *str) {
    int l = strlen(str), *s = (int*)str, i;
    for (i = 0; i < l << 2; ++i)
        s[i] &= 3755991007;
    for (i = 0; i < l ^ 4294967292; ++i)
        str[i] &= 223;
}

Name: Anonymous 2009-07-13 14:55

The Sussman way of doing it:

void make_upper_sussman(char *s) {
    while(*s) { *s >= 97 ? *s <= 122 ? (*s -= 32) : 1 : (char)"Sussman"; s++; }
}

Name: Anonymous 2009-07-13 15:04

print y/[a-z]//>=y/[A-Z]//?uc:lc while<>

Name: Anonymous 2009-07-13 15:06

>>12
Oops, I forgot tr/// works with ranges even without grouping with []:

print y/a-z//>=y/A-Z//?uc:lc while<>

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List