Solved

Formatting output for ASCII values 3-6

Posted on 1998-07-14
43
424 Views
Last Modified: 2010-04-01
For the function below I'm having trouble getting the output to display the ASCII symbol of:
3 - heart
4 - dimond
5 - club
6 - spade

What appears is a black box instead of the correct symbol.  I am using a PC which is required for this.

void Card::print ( )
{
      char pipName [ ] = "xx23456789TJQKA";
      char suitName [ ] = {3,4,5,6};            
      printf("%c%c ", pipName[_pip], suitName[_suit]);
}
0
Comment
Question by:John500
  • 19
  • 16
  • 5
  • +2
43 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1167742
that is fine.  I suspect that the problem is that you are doing this in a window and the font for the window doesn't display those symbols.  Try switching to full screen mode and see what happens.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1167743
I'm assuming that _pip and _suit are set to valid values.  you should check that.  You can just print them as integers when you try to print the symbols.
0
 

Author Comment

by:John500
ID: 1167744
Hey Todd,

How goes it?  In my spare time I'm fooling with some old projects that didn't work for one reason or another.

How do you switch to full screen mode?

John
0
 
LVL 22

Expert Comment

by:nietod
ID: 1167745
<Alt><enter>  toggles between the two.  There is also a menu option when you are in window mode, but not when you are in full screen (no menu).
0
 

Author Comment

by:John500
ID: 1167746
Todd,

I tried what you said but I get the "Properties" for what ever the cursor happens to be on at the time.  Is there some order I should follow to get the full screen mode?

I tried <alt><enter> from the desktop, the program I'm running and a few other places but as I said, the properties box pops up.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1167747
Are you running this program from a DOS box (a command prompt)?  

A command prompt uses <Alt><enter> to toggle modes and also tends to use fonts that display the DOS symbols.  
0
 

Author Comment

by:John500
ID: 1167748
To respond to your other message,

In the Card class I have:

class Card {
public:
   void set(int pip, int suit); // put a value into this card
   ...
private:
  int _pip;
  int _suit;
}

The Deck class:

class Deck{
public:
   void makeNew(); // make a pristine deck
   void print(); // print this deck, 14 cards on a line
   void shuffle(); // shuffle this deck
      Card dealOne(); // deal a card from this deck

private:
   Card _card[52];
   int _numLeft; // number of undealt cards in this deck
};

The calling function is:
void Deck::print ( )
{
      printf("Deck:\n");
      for (int i = 0; i < _numLeft; i ++)
       {      _card [i].print ( );
            // advance line after 13 cards printed
          if (((i+1) % 13) == 0)
                   printf("\n");
      }
      printf("\n");
}

0
 

Expert Comment

by:chrisbill
ID: 1167749
If the program running with a console emulation library
(like QuickWin), you're out of luck.  Those characters can
only (easily) be generated in a real DOS box.

0
 

Author Comment

by:John500
ID: 1167750
I was trying to run it by double clicking on the program from Explorer.  Since you mentioned it, I'm trying to run it from DOS.  I see what you mean about <alt><enter>.  Maybe the only problem at this point is how to get the program to run from DOS.

Once I reach the appropriate directory, what do I type to get the program to run?  I have tried "run proj2.exe" but that doesn't work.  I don't know if "run" is correct.  What works here?
0
 

Author Comment

by:John500
ID: 1167751
Todd,

I got the program to run from DOS but it automatically launches the Windows box I was seeing when I wasn't in DOS.  This happens even if I'm in the full screen mode.


0
 
LVL 22

Expert Comment

by:nietod
ID: 1167752
That source code doesn't show whethor or not the _suit and _pip are set to valid values.  In fact there must be some additional code somewhere.  

Are you running this from with you C++ IDE?  If so, try running it right from a DOS prompt.  Or try to find the EXE on your disk using the explorer and then double click on the EXE.

How are you planning to suffle?  The best method is to alternate overhand and riffle shuffles.  (I'm an expert at more than conmputers.  I'm an expert card cheat.)

0
 
LVL 22

Expert Comment

by:nietod
ID: 1167753
My last comment was before I say the last two from you.  
0
 
LVL 22

Expert Comment

by:nietod
ID: 1167754
I'll try an experiment.
0
 
LVL 84

Expert Comment

by:ozo
ID: 1167755
How do you quantify best?  Is the goal to emulate a human card cheat?
If you're looking for a random shuffle, you may want to see Q.10060202
0
 

Author Comment

by:John500
ID: 1167756
My problem is has nothing to do with shuffling, but if you are interested, I will send you the code so that you may see the whole shooting match.

The code works fine; shuffles, deals, and evaluates each hand of the 10 dealt.  My only problem is that I never got it to display the symbols.

I'm sending it now.

John
0
 
LVL 22

Expert Comment

by:nietod
ID: 1167757
Ozo, For humans, alternating the two is one of the fastest ways to randomize the deck.  Either method in sequence is less effective at randomizing.  In addition, it is harder (far from impossible) to stack the deck when alternating these shuffles.  Most techniques for stacking employ repeated shuffles of either type.  Of course, this has nothing to do with john's problem.

Anyway the whole thing about shuffling was a joke.  There is no reason to have the computer shuffle like a human.  Apparently it was not funny.  

Anyways, I did a test.  A VC 32 bit console app  from within VC produces the right characters, at least on my computer.  So some questions:
What stort of app is this?  DOS?  32 bit console?
What is this compiled with?  VC (Visual c)?  BC (Borland C)?
Can you see the desired characters in a DOS prompt program of some sort?  Like is there an ASCII chart that yoiu can look at that shows the desired characters?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1167758
>>I got the program to run from DOS but it automatically launches
>> the Windows box I was seeing when I wasn't in DOS.

That is unusual behavior.  Perhaps you weren't runnign it right.  The C++ compiler should produce an EXE of some specified name (usually the name of the project you are compiling.)  You should "move" to the directory that contains this EXE with the "CD" command.  For example if it is in "\CARDS\DEBUG", you would type "CD \CARDS\DEBUG" and press enter  Then you should just type the EXE's name and press enter.  The program should then run in the existing DOS prompt window.  It should not open a new window.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1167759
I compiled the code you sent in VC and ran it.  The output was a little hard to read, but it did have the correct symbols.  Thus the problem is in the way you are running the code, not a bug.  I'm going to send you back a file with some instructions for a test you should try.
0
 

Author Comment

by:John500
ID: 1167760
Ok, thanks.  I was running the program in DOS just as you described in your last message.  From the DOS prompt I located the directory and then the program exe.  It then launched a separate window just as though I double clicked from Explorer.

I'll let you know what happens tomorrow after using your instructions, I'm at home now.
0
 

Expert Comment

by:chrisbill
ID: 1167761
Are you running a version of Visual C++ that doesn't generate Win32 programs (as in 1.x)?  Is it a 16-bit (Win) Borland C++ program?  If so, the the window that pops up is probably either QuickWin or EasyWin.  Again, those two console emulation libraries won't properly display control characters.
0
 

Expert Comment

by:mulenga
ID: 1167762
Instead of using printf() try using _putch(int c).  You need to include <conio.h> ( assuming you are using MSVC++ )

void Card::print ( )
{
char pipName [ ] = "xx23456789TJQKA";
char suitName [ ] = {3,4,5,6};
_putch( pipName[_pip] );
_putch( suitName[_suit] );
}

0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:John500
ID: 1167763
I'm using Borland's compiler which does have the conio.h library and the putch function.  However, this does not work either.


0
 

Expert Comment

by:mulenga
ID: 1167764
The problem is these functions use DOS' "Int 21h" to print to the screen. You need to find a function that uses BIOS routines to print to the screen. The BIOS routine will print the characters as is and will not translate them like DOS does.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1167765
DOS does not translate these characters.  The functions he uses are fine.  The problem is that the characters are being displayed in a font that does not show the correct symbols.  That is what we are working to correct.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1167766
John, I don't know if you've been sending things to me or not.  but my ISP's mail server has been down (I have no idea how long and I don't know when it will be fixed).  I can still access the web so you can comunicate with me here, only I won't receive notification so I have to remember to check from time-to-time.)
0
 

Expert Comment

by:chrisbill
ID: 1167767
Ok, so you're using the Borland compiler, but is the target
a 16-bit Windows app?  How about this -- does the full path of the program appear in the title bar?  Some conio functions work in EasyWin.
0
 

Author Comment

by:John500
ID: 1167768
Yes, the full path of the program appears in the title bar.  As far as the 16-bit Windows application question goes, I'm using Borland in Windows 95.

This does lead me to another question though.  If I create a program in Windows 95 which uses the 32 bit FAT.  Does it make any difference if I take that file and run it in Windows NT which uses the 16 bit FAT?  This has nothing to do with my original question of the card symbols.

0
 
LVL 22

Expert Comment

by:nietod
ID: 1167769
I don't think you are going to be doing any programming that directly involves the FAT.   Are you?  you can use the same C++ or windows API procedures to open/close/read/write files under both systems (as well as others)  The fact that the files are stored differently has no effect  on the procedures you use to open/close/read/write the files.  The file system comes into play only if you are writing low level code, and I doubt you are.
0
 

Expert Comment

by:chrisbill
ID: 1167770
You are using Borland C++ in Win95 but you can, of course, generate 16-bit apps.  I'm convinced your problem with outputting control characters is because of the EasyWin library.

(For the second question...)
Does your program actually make calls to manipulate 32-bit FAT entries, or was it just compiled to a 32-bit FAT filesystem.  

Or, do you mean FAT32 (as in OSR2 FAT32)?  2^31 (and one bit for signing) gives you about 2.1 billion, which is the limit on a regular (non-FAT32 or NTFS) partition.  

0
 

Author Comment

by:John500
ID: 1167771
No, I won't be doing any programming that directly involves FAT.  Recently I've been thinking about whether I would have problems taking a file created on a Window's 95 machine and using it on a Windows NT machine.  I didn't know enough about the subject only that there is a difference.

No, my program doesn't make calls to manipulate 32-bit FAT entries.

If you (chrisbill) are right about my original problem, that EasyWin is the source of the problem, I'm curious to know (as Todd as mentioned) whether I can create the program using Borland, but somehow choose not to have Borland utilize EasyWin and instead create a DOS program.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1167772
Yes, that is what I've been getting at.  Borland C++ can produce true DOS programs and win 32 console programs (at least I'm 99% sure of this.  Borland C++ builder can do these)  

That is why I wanted you to create a new project for this and to look at the options you are given when you create project (or tell me what they are)  That is so we can create a DOS or win32 console project for your source.
0
 

Author Comment

by:John500
ID: 1167773
Todd,

I sent an e-mail regarding my attempts to create a new project at 1:40 pm.  Maybe our mail server is having problems.  Here is message I sent.

>...To test the font used in a regular DOS box on your >computer.  Did you see the card symbols (and others) or did you >see the squares.


Yes, I saw the card symbols.


>Can you try to create a new project and let me know what the >options are?  or try to look yourself.  There are two possible >ways to go.  A DOS program or a win 32 console program.  Both >are possible from Borland and both will work.

I have Borland's Turbo C++ version 4.5 and it appears that there are no options when creating a new project.  If I go to File, then New, the application automatically creates a new window ready for code.

When I search the On-Line Books, the only thing that comes up is "Converting DOS Applications to Windows."   This is done using EasyWin.  Nothing is obvious as to how I could change the way programs are created but if there is a way I would be interested.


The closest thing I've come up with is, after a new project is
launched/started, if I right click on that window, I get the "Edit Local Options" menu which contains the following:

Directories
Linker
Compiler
Advanced Compiler
C++ Options
Messages
Resources
Build Attributes
Make

I glanced through each of the subtopics of the above topics and nothing stood out as to creating a win 32 console program or DOS program.

Let me know what you think.


0
 
LVL 22

Expert Comment

by:nietod
ID: 1167774
Well, my e-mail certanly was havig problems yesterday.  But it seems to be okay today.

Okay the test proved that your computer can display the symbols (I was afraid you might have a weird font installed).

The depressing part it that it sounds like Borland C++ doesn't create DOS programs.  I'm not convinced about that however, but it sounds like it.  C++ Builder does create DOS and win 32 console so I would think that  BC would.  

There must be options or settings for the current project somewhere.  VC asks for the settings when you create a new project.  Perhaps BC defaults to some default setting and has options where you can change the settings.  Look around, there has to be something.
0
 

Author Comment

by:John500
ID: 1167775
Are you saying that none of the topics under the "Edit Local Options" menu look like they will do the trick?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1167776
Actually, they look pretty good.  I'm not sure how I missed them.  Unfortunately, I don't know which one to look in.  Your best bet is to have a closer look at the following ones.

Linker
Compiler
Advanced Compiler
Build Attributes
Make

linker, build, and make are your best bets.  
0
 

Author Comment

by:John500
ID: 1167777
Todd,

Under the Linker topic there is a subtopic of "Advanced" with the option to "Enable 32 bit processing."

Is this the ticket?  If so, once I choose this, will that mean the program will compile in a different way?  What is 32 bit processing anyhow?

John
0
 
LVL 22

Expert Comment

by:nietod
ID: 1167778
No.  Probably that determines whether or not 32 registers in the CPU can be used.  For the moment lets dissable that (although that probably doesn't matter).

We are looking for "target platform",  "target os", "Executable type" ...  I don't know.  There are so many posibilities.  keep looking.
0
 

Author Comment

by:John500
ID: 1167779
Looks like I may have found the general subject, how's this:

The New Project command displays the New Target dialog box where you can create and name a new project. When a new project is created by the Project Manger, a skeleton project is created. After you create the initial target for your project, you can modify the skeleton to fit your needs.
 
Once your project is created, you can change Target Attributes by selecting TargetExpert from the SpeedMenu on the Project Hierarchy.
 
When a new project is created, it inherits the option settings of the project that was open when you chose Project|New Project. If you have not opened a project in your current Turbo C++ for Windows session, the new project is given the settings of the Default Style Sheet.
0
 

Author Comment

by:John500
ID: 1167780
How's this for choices:

Target Type                   Explanation

Application (.exe)             standard application (.EXE)
Dynamic Library (.dll)             dynamic library (.DLL) file
EasyWin (.exe)                     character-mode application that
                               runs under Windows
Static Library (for.exe)[.lib] static library (.LIB) file for an
                               .exe
Static Library(for .dll)[.lib] static library (.LIB) file for a
                               .dll
Import Library (.lib)             import library (.LIB) file
Windows Help (.hpj)             Windows Help project (.HPJ) file
0
 
LVL 22

Expert Comment

by:nietod
ID: 1167781
I think you found the right area.  We don't want the easywin option, that is probably what you have.

The application (.exe) is probably for a window application so probably isn't right.  however, you might try it and then see if you have additional options for specifying a DOS application.  (That is a little like the way builder works.)

If not, it is possible that BC doesn't do DOS.  If that is the case you can get the student version of Builder for about $70  (I think).   That will do DOS.  But I would recommend you consider VC.  It is more expensive (student might be about $100) but it is far superior in most (not all) ways.  The online help is great.  The debugging is fantastic.  Those two features will save you hours alone.
0
 

Expert Comment

by:chrisbill
ID: 1167782
Borland's "Turbo" line of products (at least C++) only generate executables for _one_ environment.  That is, TC45 for Win16 only generates Win16 programs (either EasyWin or UI).  I don't believe there is any way around this.  Perhaps you could download DJGPP (http://www.delorie.com/djgpp/), it's free.

For the most part, the programs you create don't have any idea what filesystem they're running on top of.  You can safely move a FAT32 file to NTFS (and vice versa).
0
 

Author Comment

by:John500
ID: 1167783
Much thanks to all for the input!  I now have a good idea of what I've been up against.  All things considered, I'll give Todd the grade since I understand Borland better.  

crisbill, thanks for your input, you provided confirmation and good argument/fact.
0
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 1167784
You're welcome.  I would change the code to print out the letters for the symbols "C"lubs "H"earts "D"iamonds and "S"pades.  Then when you are all done, change it back to the symbols and e-mail it to me and I'll compile it for you.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now