+ 1
When we use write function in writing data to the file it gave garbage in file so what to do to avoid it?
8 ответов
+ 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
+ 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
+ 2
Kirk Schafer did you try reconfiguring ~ this just looks backwards
+ 2
Thanks for your kind help
+ 1
can we see your code so we as a community can answer this better
+ 1
Note, that code doesn't run for me. I've got both errors + warnings (last changed 25m ago)
+ 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