+ 1

When we use write function in writing data to the file it gave garbage in file so what to do to avoid it?

29th Oct 2018, 7:30 PM
Gauri Shirkande
Gauri Shirkande - avatar
8 odpowiedzi
+ 3
to me it looks like you are asking 3 questions correct ~ but if nobody knows exactly the number of records the code becomes confused and where are you retrieving from as getdata as it appears the questions are afterwards I could be wrong but the sequence looks backwards... IMO
29th Oct 2018, 8:00 PM
BroFar
BroFar - avatar
+ 3
Thanks Kirk Schafer that was way more than I expected as a professional rewrite ~ I'm busy daily with Cobol and RPG stuff so that was wonderful that you could actually step in
29th Oct 2018, 10:05 PM
BroFar
BroFar - avatar
29th Oct 2018, 7:53 PM
Gauri Shirkande
Gauri Shirkande - avatar
+ 2
Kirk Schafer did you try reconfiguring ~ this just looks backwards
29th Oct 2018, 8:15 PM
BroFar
BroFar - avatar
+ 2
Thanks for your kind help
30th Oct 2018, 3:13 AM
Gauri Shirkande
Gauri Shirkande - avatar
+ 1
can we see your code so we as a community can answer this better
29th Oct 2018, 7:37 PM
BroFar
BroFar - avatar
+ 1
Note, that code doesn't run for me. I've got both errors + warnings (last changed 25m ago)
29th Oct 2018, 8:14 PM
Kirk Schafer
Kirk Schafer - avatar
+ 1
BroFarOps 🎃👻🍬 Well...after fixing it it seems to actually be okay for ordering :/ Gauri Shirkande Your code doesn't compile because: 1. Ambiguous reference to 'data'. It appears to conflict with std::, so I just used another name. 2. Typo on write() line, syntax error, just remove the extra character. I added code to dump the output file's contents by reopening with ifstream() and reading a buffer length of 60*n. The garbage you're seeing is because you're not initializing your character arrays to any value (so you get whatever's in memory). You should wipe the arrays. ~ If you want fixed-length records you may want to wipe with spaces (character 32) ~ Otherwise you're probably going to want to add nulls (or something unique) as a delimiter, so you can tell fields apart. Test data: 3 RECORD_1 PHONE67890 RECORD_2 123PHONE45 RECORD_3 1234567890
29th Oct 2018, 10:00 PM
Kirk Schafer
Kirk Schafer - avatar