Thread: What the string?!

  1. #1
    Registered User PunchOut's Avatar
    Join Date
    Jun 2008
    norfolk, va

    What the string?!

    why does lower[] print lower and upper case letters?

    probably right in front of my face!

    #include <stdio.h>
    void alpha(char upper[26], char lower[26]);
    	char upper[26], lower[26];
    	alpha(upper, lower);
    	printf("%s\n%s\n", upper, lower);
    void alpha(char u[], char l[])
    	int i;
            char X = 65;
            char x = 97;
            for(i = 0; i < 26; i++) 
                    u[i] = X++;
                    l[i] = x++;

  2. #2
    Join Date
    Dec 2007
    You need to have room for 27 chars in your need room for the null terminator, and you need to add it.

  3. #3
    and the hat of sweating
    Join Date
    Aug 2007
    Toronto, ON
    BTW, I hope you don't use this technique in production code when in a company, since it isn't portable (i.e. it only works on ASCII platforms).
    But if you're doing this just for school then it would be a lot more readable if you replace 65 with 'A' and 97 with 'a' so people don't have to look up an ASCII chart to see if it's right or not.
    Last edited by cpjust; 11-23-2008 at 01:00 AM.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. compare structures
    By lazyme in forum C++ Programming
    Replies: 15
    Last Post: 05-28-2009, 02:40 AM
  2. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM