Thread: Using special characters in strings

  1. #1
    Math wizard
    Join Date
    Dec 2006
    Location
    USA
    Posts
    582

    Using special characters in strings

    Strings often use the characters from 0x00 to 0x7F. Short of using constant chars and include strings, is there a better way? %c and using a number didn't work (I think is referencing the memory address at 0x00000080 instead of a value).

    Code:
    char SampleString[100];
    
    const char SpecialChar80[2] = { 0x80, 0x00 }; // an alternative - null included
    
    sprintf(SampleString, "Special %c character!", 0x80); // doesn't work
    sprintf(SampleString, "Special %s characters!", SpecialChar80); // is there a more direct way?
    I know the first method doesn't work - I've tried it. The second method is a bit tedious, rather indirect - is there a better, more direct way than this, for setting an actual character, like setting 0x6E to get a lower case "n"?
    High elevation is the best elevation. The higher, the better the view!
    My computer: XP Pro SP3, 3.4 GHz i7-2600K CPU (OC'd to 4 GHz), 4 GB DDR3 RAM, X-Fi Platinum sound, GeForce 460, 1920x1440 resolution, 1250 GB HDD space, Visual C++ 2008 Express

  2. #2
    Registered User
    Join Date
    Dec 2008
    Location
    Black River
    Posts
    128
    Something like:

    Code:
    char sample_str[] = "Special \x80 character!";
    Although your first method should work just as fine.
    Stick close to your desks and never program a thing,
    And you all may sit in the standards commitee!

  3. #3
    Math wizard
    Join Date
    Dec 2006
    Location
    USA
    Posts
    582
    Ah, it is working - I have a bug in my display - an array is going out of bounds in the reverse direction. CharID[-121] will almost always cause problems. It's because I'm using a signed char when it's supposed to be unsigned. That's why it wasn't working. Thanks though.
    High elevation is the best elevation. The higher, the better the view!
    My computer: XP Pro SP3, 3.4 GHz i7-2600K CPU (OC'd to 4 GHz), 4 GB DDR3 RAM, X-Fi Platinum sound, GeForce 460, 1920x1440 resolution, 1250 GB HDD space, Visual C++ 2008 Express

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 10-29-2008, 03:22 AM
  2. Check strings which should only contain some characters.
    By qingxing2005 in forum C Programming
    Replies: 2
    Last Post: 06-17-2008, 09:32 AM
  3. Converting C strings to list of characters
    By kazbo in forum C Programming
    Replies: 11
    Last Post: 02-14-2005, 10:17 AM
  4. Special characters
    By WarBaboon in forum C++ Programming
    Replies: 2
    Last Post: 01-18-2003, 09:27 PM
  5. Scanning characters & strings
    By rain_e in forum C Programming
    Replies: 2
    Last Post: 03-04-2002, 01:43 AM

Tags for this Thread