Thread: A couple more small questions...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    119

    A couple more small questions...

    ...then I'm done asking for awhile cause I gotta take this all in!

    I've read some of this in the FAQ, and while I don't understand it all, it is definatly helpful, but I figured a little extra info from you guys doesn't hurt, but if you think I'm being lazy and don't want to awnser.....don't

    How to output to printer?

    Is there any func to tell me what speed the pc my program is running on is? If there is, I could modify what value I use when using a loop to cause a delay...I read that c has no built in "delay" function...?

    And last but certainly not least, something I'm sure I can't find in the FAQ: What file does windows.h correspond to? If I knew, I could copy windows.h and the other one to the directories of my other compiler, and write win32 console programs in it, if I'm not mistaken.

    Once again, thanks for any and all input

  2. #2
    Bond sunnypalsingh's Avatar
    Join Date
    Oct 2005
    Posts
    162
    Quote Originally Posted by Ash1981
    How to output to printer?
    See This
    Code:
    #include<stdio.h>
    int main()
    {
    char sample[]="Go To Printer";
    fprintf(stdprn,"\n%s\n",sample);
    return 0;
    }
    This method works only in the MS-DOS operating system because the "stdprn" stream is not defined by Microsoft Windows or Microsoft Windows NT.
    Last edited by sunnypalsingh; 12-31-2005 at 08:25 AM.

  3. #3
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    I think at least 2 out of the 3 questions you asked are answered in the faq

  4. #4
    Registered User
    Join Date
    Dec 2005
    Posts
    119
    I've been reading this: http://et.nmsu.edu/~etti/fall96/comp...r/printer.html

    and maybe it's just over my head, but is it just me, or does this part not make sense:
    (I included the whole paragraph for context, but pay close attn to sentence 2 and 3.)

    "[One might ask why the designers of the printer port designed the port in this manner. Assume you have a printer with no cable attached. An open usually is read as a logic one. Thus, if a logic one on the SELECT_IN, AUTOFEED and STROBE leads meant to take the appropriate action, an unconnected printer would assume it was selected, go into the autofeed mode and assume there was data on the outputs associated with the Data Port. The printer would be going crazy when in fact it wasn't even connected. Thus, the designers used inverted logic. A zero forces the appropriate action.]

    If a printer is not connected, how could it go crazy??

  5. #5
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    Here's a quick and dirty way to get the current CPU speed in Windows:

    Code:
    #include <stdio.h>
    #include <windows.h>
    
    #define CPU_KEY "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"
    #define CPU_VALUE "~MHz"
    
    int getMHz(void);
    
    int main(void)
    {
        printf("Windows reports your computer is running at %dMHz\n", getMHz());
        
        return 0;
    }
    
    int getMHz(void) 
    {
        HKEY key;
        DWORD type, size, mhz;
        DWORD bufsiz = 4;
        
        if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, CPU_KEY, 0, KEY_READ, &key) 
                != ERROR_SUCCESS) {
            /* Unable to open registry key */
            return -2;
        }
        
        if (RegQueryValueEx(key, CPU_VALUE, NULL, &type, &mhz, &bufsiz)
                != ERROR_SUCCESS) {
            /* Unable to query registry value */
            return -1;
        }
        
        return mhz;
    }
    (don't know why it's putting those spaces at the end of the CPU_KEY string tdefine but they shouldn't be there)
    Last edited by Brian; 12-31-2005 at 08:44 AM.

  6. #6
    Registered User
    Join Date
    Dec 2005
    Posts
    119
    When you say it only works in the MS DOS, does that mean it will work in the Win32 console(because I know that seems alot like DOS)? (sorry, I don't have a printer right now, otherwise I would've typed in that code, compiled it, and tested it by trying to print)

    Also, to whoever it was who provided me with the link to their tutorial on console programming (sorry, can't think of your name off the top of my head), thanks again, and I'm just about to start reading it, but I'm trying to learn a couple things on the side via this form, and trying to reinforce the basics before I tackle it...
    Last edited by Ash1981; 12-31-2005 at 08:52 AM.

  7. #7
    Registered User
    Join Date
    Dec 2005
    Posts
    119
    thanks to both of ya for the help

  8. #8
    Bond sunnypalsingh's Avatar
    Join Date
    Oct 2005
    Posts
    162
    Just by a little search I found a method which works in Windows NT as well as the MS-DOS and Windows operating systems. Here it is
    Code:
    #include <stdio.h>
    int  main()
       {
          FILE *stream;
    
          stream = fopen("PRN", "w");
          fprintf(stream, "a line of text\n");
    return 0;  
     }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. a couple of questions about System.String
    By Elkvis in forum C# Programming
    Replies: 5
    Last Post: 02-17-2009, 02:48 PM
  2. A couple of Basic questions
    By ozumsafa in forum C Programming
    Replies: 8
    Last Post: 09-26-2007, 04:06 PM
  3. Couple of Questions
    By toonlover in forum Windows Programming
    Replies: 10
    Last Post: 07-14-2006, 01:04 AM
  4. A couple questions
    By Flakster in forum C++ Programming
    Replies: 7
    Last Post: 08-09-2005, 01:22 PM
  5. A couple of questions regarding classes and strings.
    By Azimuth in forum C++ Programming
    Replies: 15
    Last Post: 06-12-2004, 10:47 AM