CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2006
    Posts
    102

    Multi-character characters?

    Is there a way to make the following possible with only a character type?

    char ch='10';


    Thanks

  2. #2
    Join Date
    Aug 2007
    Posts
    858

    Re: Multi-character characters?

    No. You want two characters - you need space to store both. It's like asking if it's possible to fit two cars into a single parking space (at least without destroying the cars).

    The typical way of storing multiple characters for a c-style string is with a char*, as in

    Code:
    const char* ch = "10";

  3. #3
    Join Date
    Dec 2005
    Location
    England
    Posts
    86

    Re: Multi-character characters?

    Perhaps you mean
    Code:
    char ch = '\10';
    ? Note that that's in octal; if you wanted a newline, you'd have to write '\12' (or simply '\n').

  4. #4
    Join Date
    Jan 2009
    Location
    Salt Lake City, Utah
    Posts
    82

    Re: Multi-character characters?

    I know it's possible to define a four character literal, like 'abcd', which could then be held in a 32bit integer. Two characters would probably do something similar
    Intel Core Duo Macbook w/ Mac OS 10.5.6
    gcc 4.2.1 (i386-apple-darwin9.1.0) and Xcode 3.1.1

  5. #5
    Join Date
    Feb 2009
    Location
    Ukraine
    Posts
    64

    Re: Multi-character characters?

    Why don't you try to experiment yourself writing something like
    Code:
    #include <stdio.h>
    
    int main()
    {
      char t = '10'; // compiler probably will warn you, but compilation will not fail
      putchar(t);
      printf("\ncontent = 0x&#37;X\n", t); // here you will see that yes, it is possible, but the value is truncated to sizeof, as expected
      return 0;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured