473,545 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Merge File without copies

Hi All,

I have problem whit this program, because the output file print copies
but only at the end of file, and the file does not have two copies of
the same element.

Example of elements in the two file:

11 Sodium Na 22.99
20 Calcium Ca 40.08

------------------------------------------------------------------------
Structure

typedef struct{
int atomic_number;
char name[MAX];
char symbol[MAX];
double weight;
}chemical_t;

------------------------------------------------------------------------

while(!feof(ele ment_1)){
fscanf(element_ 1,"%d%s%s%lf",& chemical_1.atom ic_number,
chemical_1.name ,
chemical_1.symb ol,
&chemical_1.wei ght);
while(!feof(ele ment_2)){
fscanf(element_ 2,"%d%s%s%lf",& chemical_2.atom ic_number,,
chemical_2.name ,
chemical_2.symb ol,
&chemical_2.wei ght);

for(i = 0; i < el_1; i++){
if(chemical_1.a tomic_number < chemical_2.atom ic_number){
fwrite(&chemica l_1, sizeof(chimico_ t), 1, element);
fscanf(element_ 1,"%d%s%s%lf",& chemical_1.atom ic_number,
chemical_1.name ,
chemical_1.symb ol,
&chemical_1.wei ght);
}

else{
for(j = 0; j < el_2; j++){
fwrite(&chemica l_2, sizeof(chimico_ t), 1, element);
fscanf(element_ 2,"%d%s%s%lf",& chemical_2.atom ic_number,,
chemical_2.name ,
chemical_2.symb ol,
&chemical_2.wei ght);

}//end for
}//end else
}//end for
}//end while
}//end while
Thanks
Jan 24 '07 #1
5 2739
Defected <de**********@g mail.comwrote:
I have problem whit this program, because the output file print copies
but only at the end of file, and the file does not have two copies of
the same element.
Sorry, parse error here. Can you restate that in some way that makes
a bit more sense?
Example of elements in the two file:
11 Sodium Na 22.99
20 Calcium Ca 40.08
------------------------------------------------------------------------
Structure
typedef struct{
int atomic_number;
char name[MAX];
char symbol[MAX];
double weight;
}chemical_t;
------------------------------------------------------------------------
while(!feof(ele ment_1)){
First problem: you can use feof() only reasonably _after_ you have
read from a file - it's there to tell you if you hit EOF during the
read, it can't predict if the next read will lead to hitting EOF.
fscanf(element_ 1,"%d%s%s%lf",& chemical_1.atom ic_number,
chemical_1.name ,
chemical_1.symb ol,
&chemical_1.wei ght);
while(!feof(ele ment_2)){
fscanf(element_ 2,"%d%s%s%lf",& chemical_2.atom ic_number,,
chemical_2.name ,
chemical_2.symb ol,
&chemical_2.wei ght);
for(i = 0; i < el_1; i++){
What are 'el_1' and 'el_2'? And why don't you worry about reaching
EOF here?
if(chemical_1.a tomic_number < chemical_2.atom ic_number){
fwrite(&chemica l_1, sizeof(chimico_ t), 1, element);
fscanf(element_ 1,"%d%s%s%lf",& chemical_1.atom ic_number,
chemical_1.name ,
chemical_1.symb ol,
&chemical_1.wei ght);
}
else{
for(j = 0; j < el_2; j++){
fwrite(&chemica l_2, sizeof(chimico_ t), 1, element);
fscanf(element_ 2,"%d%s%s%lf",& chemical_2.atom ic_number,,
chemical_2.name ,
chemical_2.symb ol,
&chemical_2.wei ght);
I actually can't figure out what this is supposed to be doing.
But if you don't want any doubles in the output file and have
all elements sorted you will have to read in all elements from
both files, eliminate repetitions and sort before writing them
out to the output file.

Or is there something about the input files you didn't tell, e.g.
that they are already sorted by atom numbers in ascending order?
In that case things would be quite a bit simpler. You would need
something like the following pseudo-code (e1 and e2 stand for the
elements you read from the first and second file and f1 and f2
for the first and second file):

1: read e1 from f1
IF read failed because of EOF of f1 {
copy_rest_of( f2 )
DONE
}

read e2 from f2
IF read failed because of EOF of f2 {
copy_rest_of( f1 )
DONE
}

2: IF e1 == e2 {
write out e1 /* write out e2 would also do */
GOTO 1
} ELSE IF e1 < e2 {
write out e1
read new e1 from f1
IF read failed because of EOF of f1 {
write out e2
copy_rest_of( f2 )
DONE
}
} ELSE {
write out e2
read new e2 from f2
IF read failed because of EOF of f2 {
write out e1
copy_rest_of( f1 )
DONE
}
}
GOTO 2

where copy_rest_of() is a function or some code that just copies
everything not yet read from an input file straight to the output
file (and 'DONE' stands for "get out of this function"). Of course,
things can be a bit re-ordered (and don't use goto's unless there
isn't a very good reason;-), the pseudo-code is just for pointing
out the basic logic you would need with already sorted input files.

Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\______________ ____________ http://toerring.de
Jan 24 '07 #2
Defected wrote:
Hi All,

I have problem whit this program, because the output file print
copies but only at the end of file, and the file does not have two
copies of the same element.
This is not a program, it's a piece of one. Post a complete, minimal
program that demonstrates the problem. Also, thoroughly explain what
you expected the program to do, and what it did instead.

Brian
Jan 25 '07 #3
Jens Thoms Toerring <jt@toerring.de wrote:
I have problem whit this program, because the output file print copies
but only at the end of file, and the file does not have two copies of
the same element.
Sorry, parse error here.
Seems more like an error with the semantic analyzer - the grammar is
passable.

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gma il.com | don't, I need to know. Flames welcome.
Jan 25 '07 #4
Christopher Benson-Manica <at***@norge.fr eeshell.orgwrot e:
Jens Thoms Toerring <jt@toerring.de wrote:
I have problem whit this program, because the output file print copies
but only at the end of file, and the file does not have two copies of
the same element.
Sorry, parse error here.
Seems more like an error with the semantic analyzer - the grammar is
passable.
You're right;-) Even "whit" seems to be a valid token as my dictionary
tells me...
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\______________ ____________ http://toerring.de
Jan 25 '07 #5
Defected wrote:
Hi All,

I have problem whit this program, because the output file print copies
but only at the end of file, and the file does not have two copies of
the same element.
I suggest breaking down each task to a seperate callable function. Even
if it's overkill, it'll help you and others to understand your code's
flow of execution more easily. Also errors can be easily isolated.

I also suggest putting in a few printf()'s and assert()'s to check the
runtime behaviour. Any wrong value or condition can be identified right
upto the source line number. Use the __LINE__ macro with printf().

Also, in future, post a minimal compilable example that demostrates
your problem. It enables others to run your source through their
compilers, lint or whatever and minimise the time needed to tediously
read through the whole source.

Snippets of source code are almost always, very difficult to diagnose
or comment about.

Also see this FAQ:
<http://c-faq.com/stdio/index.html>

Many of the FAQs on that page may be relevant to your program's
problems, like 12.2, 12.41 etc.

Jan 25 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5570
by: Andy Davis | last post by:
I have set up a mail merge document in Word 2003 which gets its data from my Access 2000 database. I want to set up a button on a form that: 1. runs the query to provide the dat for the merge document in Word; 2. opens the document and runs the merge process for the new data. I have managed to write the code to perform step 1 ok, but I'm...
14
1748
by: Michael R. Copeland | last post by:
I'm writing an application that requires an "intelligent merge" of 2 files. That is, equal data has a "preferred source" that I want to write out. What I have works, I believe, but it seems horribly cumbersome (having to set the input variables to ""...). Is there a better way? TIA while ((!feof(wf3)) || (!feof(wf1))) { if...
0
2734
by: Shiraz | last post by:
Hi I have a question regarding the functionality of merge modules. Since this relates to my previous queries, I'll just give you a brief background on the topic. I had to make an installer for an application which was to share dlls with another application and these dlls were not self-registering. Someone on the forum suggested a few...
8
1527
by: mesterak | last post by:
I'm trying to write a text log file processor but am having significant performance issues. * On average, there are about 100-200 files to process each file being about 1MB in size. * Typically there are ~600k to 1m lines to process total. Every line in each log file typically contains a date, a time, follwed by a textual message *...
1
4287
by: mjobbe | last post by:
I have an installer that requires three merge modules (ATL, CRT, and MFC), and after adding them in, I get the following warnings when I build the MSI: WARNING: Two or more objects have the same target location ('\8.0.50727.42.cat') WARNING: Two or more objects have the same target location ('\8.0.50727.42.cat')
7
590
by: Defected | last post by:
Thanks all for help, I have tried this code but it's don't work. -------------------------------------------------------------------- Structure typedef struct{ int atomic_number; char name;
4
7216
by: Tom Jones | last post by:
I have an application that was originally built using Visual Studio 2003 that I upgraded to Visual Studio 2005. When I attempt to build the *.msi file in the deployment project, I am getting a compile error stating that it cannot find: "C:\Program Files\Common Files\Merge Modules\Crystal_regwiz2003.msm" I am not sure where to get this file...
5
16699
by: Mark Chambers | last post by:
Hi there, Can anyone explain the following (very) simple scenario. 1) I make an exact copy of my "DataSet" and delete one record from a given table (in the copy) 2) I invoke "DataSet.GetChanges()" on the above copy and pass the results to "DataSet.Merge()" on the original copy 3) If I now inspect the original copy, it shows that the...
7
7231
by: giladp1 | last post by:
I found Albert Kallal's great "Super easy Word Merge" code in his site at: http://www.members.shaw.ca/AlbertKallal/msaccess/msaccess.html Thanks Albert so much for sharing this. I am looking for any comments about the use of the docmd.transfertext method instead of the code Albert used for creating the text file. Also, perhaps some...
1
6535
by: Esther Lane | last post by:
Hello! First off, many many thanks to Albert who wrote the Mail Merge code for MS Access I am using. It has been working beautifully for a few years. However, my client just (without notice!) upgraded from Access 2000 to Access 2007. Now that component is failing. The merge is building the data source file fine (text file named...
0
7682
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
6009
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5351
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5069
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
3479
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...
0
3465
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1911
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1037
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
734
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.