Click here to Skip to main content
15,885,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I made a "C" program that builds a year calendar and writes all of the results to an output text file. The problem is that when I edit the file, all of the characters are all messed up. So when I go to print out this file, all of the file contents are all printed in a messed fashion, and then it increases the of pages that are printed out; and the print outs look like a mess. But if I type the file out to the screen, they look nice appearing on the screen. So how can I get what write out to the output file appear nice as I print it out on a printer? I do request some help.

What I have tried:

I have written a "C" program which produces a text calendar and the results is put into a text file. If you type the file out on the screen, they look nice, but if you print them out, the output from the printer is garbage and it is not the way I sent it to the file. The program works, but process of program to output file to printer produces garbage from a printer..
Posted
Updated 29-Jun-22 18:55pm
Comments
The Other John Ingram 29-Jun-22 18:26pm    
could you post an example of the output from the printer?

Quote:
C printing a text file and have it in correct print form.

Congratulations, you have been extremely careful to not give any useful information.
at least you need to provide related source code and text file before and after changes.

If you ask 100 programmers their solution for same problem, you get 120 solutions. We can't guess anything you have done.
 
Share this answer
 
Comments
Member 15028314 30-Jun-22 21:37pm    
send me an quiet/not-known email address and I'll send you the code, but don't make the email known. Ok. I'm not one whom sends out their hard work to people to browse. But I'll do it. It was an idea I acquired off the Internet, and then I blew it up to its size, and added function call of my own to add features to it.
Text files aren't magic: they are literally just a stream of characters which have to be interpreted by the application that reads them to apply any formatting.
Equally, in order to be readable at a later date you have to apply some formatting to your data when you write it to the file.
For example, if you print two dates into a file then what you get is just a string containing a number:
Text:
0101202111122022
Unless your application processes that as "two character day, two character month, four character year, character day, two character month, four character year" when it reads it back, it's going to be useless to you. Worse, if you don't specifically add you leading zeros:
Text:
11202111122022
then when you try to read it back your app has pretty much no chance at all of getting meaningful data!
The simplest form of formatting is to add line breaks to separate values:
Text:
01012021
11122022
Now you app can see where date entries start and end, which makes life a lot easier, both for your app to process, and human beings to read and understand!

One of the simplest ways to format a file is called CSV (Comma Separated Values) and its does exactly what the name suggests: each line is a row of related data items:
Text:
1,1,2021,"C programming 101","Room 17"
11,12,2022,"Update Resume",""
You will find a more detailed description of CSV data here: Comma-separated values - Wikipedia[^]

But file formats - even for text based files - can get a lot more complicated and useful: JSON[^] is very popular, as is XML[^] but they take quite some effort to produce / process from scratch!

I'd start by sitting down and working out what you need to store, and thinking about how you need to store it so you can retrieve it sensibly.
 
Share this answer
 
Comments
Member 15028314 30-Jun-22 21:44pm    
Hello OriginalGriff, it's been a long time since I have communicated with you. The problem I've been having is contained in a completed project(function). It is a small calendar that I blew up to a big size and added a few nice features to it. Of doing all of the programs that I am currently working, I have learned a lot on my own. I maybe soon sending the function to Patrica T., if she responds right.
OriginalGriff 1-Jul-22 1:11am    
"Patrice T", not "Patrica T"
It's a French masculine first name.
Member 15028314 19-Jul-22 14:11pm    
Hello OriginalGriff, I figured out my problem via my son, but I do not understand the answer why. My son told me to use notepad++, not MS-notepad, to see the actual calendar in month-form. I could see the month -calendars perfectly that I sent to a text file. And so I printed out a couple of months of the year, from notepad++, not MS-notepad. The output of NOTEPAD++ was excellent. Can you figure out why OriginalGriff?? And Thanks again...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900