473,569 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Formatting output text file

Sheepman
24 New Member
My quest, to put 100 random numbers in ten rows of ten. Then output the same to the screen and a file. My screen output is working,yeah! Text file, not so much. The data is getting there but not formated. If word wrap is off it's a single row. If word wraps on, well ... it wraps. I've considered sizing the notebook window to wrap at the tenth character but I don't think the TA working on his Phd will buy it. Help please! My code for this portion is below:

Expand|Select|Wrap|Line Numbers
  1. void tenByTen(int firstArray[])
  2. {
  3. char yourFileName [80];
  4. int d1, d2;
  5. //Prompt user for file name to store array
  6. cout << "Enter name of file to store your randomly generated numbers: " << endl;
  7. cin >> yourFileName;
  8. ofstream outfile (yourFileName, ios::out);//create and open file
  9. if (!yourFileName)//errorcheck
  10. {
  11.     cout << "Error opening your file " << endl;
  12. }//close error check
  13. //fomat array output to 10 x 10
  14.  
  15. for (d1 = 0; d1 <= 9; d1++)
  16. {
  17.     for (d2 = 0; d2 <= 9; d2++)
  18.     {
  19.      cout << setw(5) << firstArray[(d1 * 10) + d2];//write to screen
  20.      outfile << setw(4) << firstArray[(d1 * 10) + d2];//write to file     
  21.     }//close nested for
  22.     cout << endl;
  23. }//close for
  24. outfile.close();
  25. }//close tenBy
  26.  
Jul 10 '07 #1
4 3519
scruggsy
147 New Member
Look how you are sending a message to the screen to tell it to start a new line after every 10 numbers:
Expand|Select|Wrap|Line Numbers
  1. cout << endl;
It works, right?
All you need to do is send a similar message to your file at the same time, telling it to start a new line as well.
Jul 10 '07 #2
mohsin
19 New Member
Look how you are sending a message to the screen to tell it to start a new line after every 10 numbers:
Expand|Select|Wrap|Line Numbers
  1. cout << endl;
It works, right?
All you need to do is send a similar message to your file at the same time, telling it to start a new line as well.
look all u need to so is to write
outfile<<endl;
after cout<<endl;


given below
for (d1 = 0; d1 <= 9; d1++)
{
for (d2 = 0; d2 <= 9; d2++)
{
cout << setw(5) << firstArray[(d1 * 10) + d2];//write to screen
outfile << setw(4) << firstArray[(d1 * 10) + d2];//write to file
}//close nested for
cout << endl;
outfile<<endl;
}//close for
outfile.close() ;
}//close tenBy
Jul 10 '07 #3
Sheepman
24 New Member
Look how you are sending a message to the screen to tell it to start a new line after every 10 numbers:
Expand|Select|Wrap|Line Numbers
  1. cout << endl;
It works, right?
All you need to do is send a similar message to your file at the same time, telling it to start a new line as well.
I spent 4 or 5 hours trying to figure this out. I kept using
Expand|Select|Wrap|Line Numbers
  1. cout<<endl;
instead of
Expand|Select|Wrap|Line Numbers
  1. outfile<<endl;
. I've only been doing this 4.5 weeks. It's the little things that really seem to kill me.
Jul 10 '07 #4
Sheepman
24 New Member
look all u need to so is to write
outfile<<endl;
after cout<<endl;
Don't I look silly!

My book doesn't say anything about this. I kept trying to use
Expand|Select|Wrap|Line Numbers
  1. cout<<endl;
in every combination imaginable. Inside the brackets, outside the brackets, commenting out the write to screen portion. I'm not to clear on how to debug yet. So I don't know how to use it to my advantage, to see at what point the program stops outputting my expected results.
Jul 10 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
3753
by: Tom Petersen | last post by:
I am using a response.write to test the formatting of the output. I am supposed to get this: BEGIN:VCALENDAR VERSION:1.0 BEGIN:VEVENT DTSTART:20051022T090000Z DTEND:20051022T090000Z LOCATION;ENCODING=QUOTED-PRINTABLE:Library UID:20051022T090000ZI-request DESCRIPTION;ENCODING=QUOTED-PRINTABLE:test
6
1726
by: Tom Petersen | last post by:
Here is a little more info, sorry should have explained what my final goal was. I am creating a .vcs file from a form to import into Outlook. I was just testing the output on screen then pasting that into a file, after removing the extra white space, and inserting line breaks. The data is valid, but the formatting into the file isn't...
6
2946
by: shoo | last post by:
Any one know how to do this? thank Write a simple text-formatting program that produces neatly printed output from input text containing embedded command lines that determine how to format the output; all lines begin with a period are command lines. The task of the program is to collect words from input lines, fill output lines with...
1
3026
by: vbnetrookie | last post by:
Hi all, This is my first batch file and I want to query a database and output it in a textfile. Up to now that works, the only problem is the formatting in the text file. It's all screewed up...lines aren't lined up and columns aren't right....how do you format the result from a query to a text file. Here's my code: osql.exe -S MYMACHINE...
1
10164
by: Riko Eksteen | last post by:
Hi I'm reading an xml file into an XmlDocument, adding some nodes, and writing it back out. I would like the nodes I add to assume the same level of indeting as the rest of the document. (I load the document with PreserveWhiteSpace = true.) I thought I could do this by using an XmlTextWriter with Formatting set to Formatting.Indented,...
8
3498
by: Mike MacSween | last post by:
tblCourses one to many to tblEvents. A course may have an intro workshop (a type of event), a mid course workshop, a final exam. Or any combination. Or something different in the future. At the moment the printed output is usually going to Word. It's turning into an unholy mess, because I'm having to prepare umpteen different Word...
6
2713
by: shoo | last post by:
Any one know how to do this? thank Write a simple text-formatting program that produces neatly printed output from input text containing embedded command lines that determine how to format the output; all lines begin with a period are command lines. The task of the program is to collect words from input lines, fill output lines with...
2
6315
by: Ken Wilson | last post by:
I am writing and .xml file and am not getting the formatting I would like. The portion of the code that is giving me problems is as follows; XmlTextWriter tw = new XmlTextWriter(filename); tw.Formatting = Formatting.Indented; tw.WriteStartDocument(); tw.WriteStartElement("MyRoot"); tw.WriteStartElement("MyString);
6
3833
by: Glen | last post by:
Hello again, I don't blame anyone for not answering my last post, since I obviously hadn't spent much time researching, but I've come a little ways and have another question. How can I better format text output to a QTextEdit object? I'm inserting 5 columns into each row. When I write the info to a file, it looks like the following: ...
10
2113
by: sara | last post by:
Hi - I have a report that is 14 columnar sub-reports (Line up: Position- holders in each of our 14 locations - Manager, Assistant Manager, Receiving, Office, etc). I output directly to PDF (using ConvertReportToPDF from this site - Stephan Lebans) The formatting - Outlines on some fields - do not appear on subreports
0
7695
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8119
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7668
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5218
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.