How to print directly from compile screen?

This is a discussion on How to print directly from compile screen? within the C Programming forums, part of the General Programming Boards category; Am I correct in saying that this so far has flpt point to lpt:1, and I then send the text ...

  1. #31
    Registered User
    Join Date
    Mar 2008
    Posts
    65
    Am I correct in saying that this so far has flpt point to lpt:1, and I then send the text "Test print.\n\nTest print.\n\nTest print.\n\n" to the file which is allegedly the printer? Clarification is an essential thing to attain, and so that is my first question.

    Secondly, I have sent text to the printer, but now need to tell flpt to print with out using the syntax
    Code:
    fprintf(flpt, JUST PRINT THE TEXT, DARN YOU!!!!!!!!);
    Thirdly, windows has a built in print command that I can access through the system?

  2. #32
    Registered User
    Join Date
    Mar 2008
    Posts
    65
    Okay, so I've been getting somewhere. I will just print from a notepad file, but now I need some help. Swap your username for "USERNAME", and the question marked part should be mostly all that's missin. Here's what I got:
    [code]
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
      FILE *flpt;
      flpt = fopen("C:\\Documents and Settings\\USERNAME\\Desktop\\test.txt", "w");
      if (flpt == NULL) { 
         perror("open C:\\Documents and Settings\\USERNAME\\Desktop\\Test.txt"); 
         exit(1); 
      }
      fprintf(flpt, "Test print.\n\nTest print.\n\nTest print.\n\n");
      system(PRINT [/*?????????*/] [flpt]);
    }
    [\code]
    I found the PRINT system function and syntax at the previously suppled website (thanks again), but I don't get the first part. Thanks!

  3. #33
    Registered User
    Join Date
    Mar 2008
    Posts
    65
    Also, PRINT reads as an error, it is expected to be defined first.

  4. #34
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    system() expects to be passed a string. And system commands that are executed with it can only access files by filename, not by the FILE* that you have. I suspect you want something like this.
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
      FILE *flpt;
      flpt = fopen("C:\\Documents and Settings\\USERNAME\\Desktop\\test.txt", "w");
      if (flpt == NULL) { 
         perror("open C:\\Documents and Settings\\USERNAME\\Desktop\\test.txt"); 
         exit(1); 
      }
      fprintf(flpt, "Test print.\n\nTest print.\n\nTest print.\n\n");
      fclose(flpt);
      system("PRINT \"C:\\Documents and Settings\\USERNAME\\Desktop\\test.txt\"");
    }
    That's the built-in print command that I believe I mentioned earlier -- maybe not, I can't remember.

    Note the quotes surrounding the filename for PRINT -- because the name has a space in it, these quotes are required. (I'm talking about the escaped quotes, \".)
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #35
    Registered User
    Join Date
    Mar 2008
    Posts
    65
    Great, no error reports! Now I just have o get my hands on a printer... Thanks though, man!

  6. #36
    Registered User
    Join Date
    Mar 2008
    Posts
    65
    Okay. Haven't gotten to a printer yet, but one more hopefully quick thing. The file doesn't need to exist, because it has "w" after I open it, so it will be create if it doesn't exist. Now, how do I delete it when I'm done so it doesn't have to be there?

  7. #37
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    use the remove() function:
    http://www.hmug.org/man/3/remove.php

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #38
    Registered User
    Join Date
    Jan 2008
    Posts
    32
    is there any way i can redirect the output to a network printer installed on the local network..

  9. #39
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by technosavvy View Post
    is there any way i can redirect the output to a network printer installed on the local network..
    Read the posts in this thread.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #40
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Quote Originally Posted by technosavvy View Post
    is there any way i can redirect the output to a network printer installed on the local network..
    Assuming that you're on a Windows network, You can use NetUseAdd to establish a connection to a remotely *shared* printer. Essentially, you would be programmatically executing the equivalent of the following NET USE command line statements:

    Assume PRTA is the current network printer being used by your workstation, you would first delete this connection as follows:

    NET USE LPT1 /DEL

    Now you wish to use PRTB as follows

    NET USE LPT1 \\SomeServer\PRTB

    Your have just changed your printing thru LPT1 from PRTA to PRTB. Again, assuming that PRTB is a SHARED printer.

  11. #41
    Registered User
    Join Date
    Mar 2008
    Posts
    65
    The remove function doesn't get rid of the file. Maybe I was unclear, but I want Test.txt to be deleted if that is easy.

    Also, when I create the file, can it be called a different name according to a string?(only matters if I can't delete it)

    Thanks
    -Matt

  12. #42
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by mcotter222 View Post
    The remove function doesn't get rid of the file. Maybe I was unclear, but I want Test.txt to be deleted if that is easy.

    Also, when I create the file, can it be called a different name according to a string?(only matters if I can't delete it)

    Thanks
    -Matt

    remove should certainly delete the file - that's what the function is for, if it doesn't do that, then something is broken in your C library.

    Quote Originally Posted by Man page
    The remove() function removes the file or directory specified by path.
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  13. #43
    Registered User
    Join Date
    Mar 2008
    Posts
    65
    All I did was add this line to the end
    Code:
    remove("C:\\Documents and Settings\\USERNAME\\Desktop\\Test.txt");
    and nothing happened when I compiled it besides making the file Test.txt.

  14. #44
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Quote Originally Posted by mcotter222 View Post
    All I did was add this line to the end
    Code:
    remove("C:\\Documents and Settings\\USERNAME\\Desktop\\Test.txt");
    and nothing happened when I compiled it besides making the file Test.txt.
    You have to use the DOS 8.3 naming convention as opposed to the NTFS naming convention. For example, your remove statement should look something like this:

    Code:
    remove("C:\\Docume~1\\USERNAME\\Desktop\\Test.txt");
    EDIT: My bad. remove will work with the NTFS naming convention. Disregard the DOS 8.3 suggestion
    Last edited by BobS0327; 04-11-2008 at 10:08 PM. Reason: My mistake

  15. #45
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    I can't imagine that would happen unless you were using a rather old DOS compiler. Is that required even for, say, programs compiled with Dev-C++?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Page 3 of 5 FirstFirst 12345 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How does this user get screen to run under root?
    By Overworked_PhD in forum Tech Board
    Replies: 2
    Last Post: 06-28-2009, 09:31 AM
  2. merging linked lists
    By scwizzo in forum C++ Programming
    Replies: 15
    Last Post: 09-14-2008, 05:07 PM
  3. Feedback: Functional Specification Wording
    By Ragsdale85 in forum C++ Programming
    Replies: 0
    Last Post: 01-18-2006, 03:56 PM
  4. how to print a file on the screen
    By tameeyore in forum C Programming
    Replies: 4
    Last Post: 09-18-2005, 12:00 PM
  5. Print Screen
    By /\/\ E /\/ @ in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 08-11-2002, 05:37 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21