Mixed Letter Converter

This is a discussion on Mixed Letter Converter within the C++ Programming forums, part of the General Programming Boards category; Yeah I know, I made it in 10 seconds....

  1. #16
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Yeah I know, I made it in 10 seconds.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  2. #17
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    CornedBee: Well, here's a portable toupper() which should work between character sets:

    Code:
    char toupper(char c)
    {
        static const char *lowercase = "abcdefghijklmnopqrstuvwxyz";
        static const char *uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        int i;
        for(i = 0; i < 26; ++i)
        {
            if(c == lowercase[i])
            {
                return uppercase[i];
            }
        }
        return c;
    }
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  3. #18
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    True. It's also slow.

    Don't get me wrong. Considering how stupid the original assignment is, pretty much everything is fine to turn in IMO.
    I was just talking about using 97 instead of 'a', 65 instead of 'A', and 32 instead of 'a' - 'A'. To me, the numbers are far less readable, and they have a small portability impact too.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How do I ...
    By geekrockergal in forum C Programming
    Replies: 21
    Last Post: 02-07-2009, 09:40 AM
  2. counting letter occurences in a string
    By pjr5043 in forum C++ Programming
    Replies: 35
    Last Post: 05-05-2008, 09:18 PM
  3. Advice requested, Code makes sense to me, not compiler
    By andrew.bolster in forum C Programming
    Replies: 53
    Last Post: 01-06-2008, 12:44 PM
  4. help using strings and mapping
    By trprince in forum C Programming
    Replies: 29
    Last Post: 12-01-2007, 03:01 PM
  5. Big Letter became small letter
    By cogeek in forum C Programming
    Replies: 27
    Last Post: 12-13-2004, 01:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21