473,320 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

File

Hi All,

I have need to write a void function that will merge the contents of two
text file containing chemical elements sorted by atomic number and will
produce a sorted file of binary records. The funcion's parameters will
be three file pointers.
Each text file line contain for example:

11 Sodium Na 22.99
20 Calcium Ca 40.08

The function can assume that one file does not have two copies of the
same element and that the binary output files should have this same
property.
When one of the input files is exhausted, do not forget to copy the
remaining elements of the other input file to the result file.

I have created the function merge that create a binary file with all the
elements, but I don't understand ,how I can make to produce a binary
file without duplicates elements.

Structure

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

void merge(FILE *element_1, FILE *element_2, FILE *element){

chemical_t chemical;
chemical_t chemical_1;
chemical_t chemical_2;

element = fopen("text_b.dat", "wb");
element_1 = fopen("text1.txt", "rb");

fscanf(element_1,"%d%s%s%lf",&chemical_1.atomic_nu mber,
chemical_1.name,
chemical_1.symbol,
&chemical_1.weight);
while(!feof(element_1)){
fwrite(&chemical, sizeof(chemical_t), 1, element);
fscanf(element_1,"%d%s%s%lf",&chemical_1.atomic_nu mber,
chemical_1.name,
chemical_1.symbol,
&chemical_1.weight);

}
fclose(element_1);
element_2 = fopen("text2.txt", "rb");

fscanf(element_2,"%d%s%s%lf",&chemical_2.atomic_nu mber,
chemical_2.name,
chemical_2.symbol,
&chemical_2.weight);
while(!feof(element_2)){
fwrite(&chemical, sizeof(chemical_t), 1, element);
fscanf(element_2,"%d%s%s%lf",&chemical_2.atomic_nu mber,
chemical_2.name,
chemical_2.symbol,
&chemical_2.weight);
fclose(element_2);
fclose(element);

}
Thanks
Jan 23 '07 #1
7 2100

Defected wrote:
Hi All,

I have need to write a void function that will merge the contents of two
text file containing chemical elements sorted by atomic number and will
produce a sorted file of binary records. The funcion's parameters will
be three file pointers.
Each text file line contain for example:

11 Sodium Na 22.99
20 Calcium Ca 40.08

The function can assume that one file does not have two copies of the
same element and that the binary output files should have this same
property.
When one of the input files is exhausted, do not forget to copy the
remaining elements of the other input file to the result file.

I have created the function merge that create a binary file with all the
elements, but I don't understand ,how I can make to produce a binary
file without duplicates elements.
You have created a function which should be called "concatenate"...

To merge two files, you read records from both inputs, decide which
record to write to the output, read another file from the appropriate
input, and so on...

Jan 23 '07 #2

mark_blue...@pobox.com wrote:
Defected wrote:
Hi All,

I have need to write a void function that will merge the contents of two
text file containing chemical elements sorted by atomic number and will
produce a sorted file of binary records. The funcion's parameters will
be three file pointers.
Each text file line contain for example:

11 Sodium Na 22.99
20 Calcium Ca 40.08

The function can assume that one file does not have two copies of the
same element and that the binary output files should have this same
property.
When one of the input files is exhausted, do not forget to copy the
remaining elements of the other input file to the result file.

I have created the function merge that create a binary file with all the
elements, but I don't understand ,how I can make to produce a binary
file without duplicates elements.

You have created a function which should be called "concatenate"...

To merge two files, you read records from both inputs, decide which
record to write to the output, read another file from the appropriate
Naturally that should say "read another record...."
input, and so on...
Jan 23 '07 #3
Thanks but how I can make ? I have not idea.
ma**********@pobox.com ha scritto:
Defected wrote:
>Hi All,

I have need to write a void function that will merge the contents of two
text file containing chemical elements sorted by atomic number and will
produce a sorted file of binary records. The funcion's parameters will
be three file pointers.
Each text file line contain for example:

11 Sodium Na 22.99
20 Calcium Ca 40.08

The function can assume that one file does not have two copies of the
same element and that the binary output files should have this same
property.
When one of the input files is exhausted, do not forget to copy the
remaining elements of the other input file to the result file.

I have created the function merge that create a binary file with all the
elements, but I don't understand ,how I can make to produce a binary
file without duplicates elements.

You have created a function which should be called "concatenate"...

To merge two files, you read records from both inputs, decide which
record to write to the output, read another file from the appropriate
input, and so on...
Jan 23 '07 #4

Don't top-post. I have moved your reply to where it belongs...
ma**********@pobox.com ha scritto:
>Defected wrote:
>>Hi All,

I have need to write a void function that will merge the contents of two
text file containing chemical elements sorted by atomic number and will
produce a sorted file of binary records. The funcion's parameters will
be three file pointers.
Each text file line contain for example:

11 Sodium Na 22.99
20 Calcium Ca 40.08

The function can assume that one file does not have two copies of the
same element and that the binary output files should have this same
property.
When one of the input files is exhausted, do not forget to copy the
remaining elements of the other input file to the result file.

I have created the function merge that create a binary file with all the
elements, but I don't understand ,how I can make to produce a binary
file without duplicates elements.

You have created a function which should be called "concatenate"...

To merge two files, you read records from both inputs, decide which
record to write to the output, read another file from the appropriate
input, and so on...
Thanks but how I can make ? I have not idea.
Read a line from file 1 (element A)
Read a line from file 2 (element B)
In a loop:
if elementB is alphabetically before A,
write B
read new element B
else
write A
read new element A
endif
endloop

Remember to add code that handles the end-of-file,
so you don't try to read past it.

--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Software Reuse Project

Jan 23 '07 #5
Defected wrote:
>
Thanks but how I can make ? I have not idea.
We don't do homework. We may help after a proper effort. We also
intensely dislike top-posting. Your answer belongs after the
material to which you reply. See the links below.

--
Some informative links:
<http://www.catb.org/~esr/faqs/smart-questions.html>
<http://www.caliburn.nl/topposting.html>
<http://www.netmeister.org/news/learn2quote.html>
<http://cfaj.freeshell.org/google/ (taming google)
<http://members.fortunecity.com/nnqweb/ (newusers)
Jan 23 '07 #6
Hello thanks for help,
but I don't understand how i can read, line from file 1 (element A)

because I use this:

fscanf(element_1,"%d%s%s%lf",&chemical_1.atomic_nu mber,
chemical_1.name,
chemical_1.symbol,
&chemical_1.weight);
while(!feof(element_1)){
fscanf(element_1,"%d%s%s%lf",&chemical_1.atomic_nu mber,
chemical_1.name,
chemical_1.symbol,
&chemical_1.weight);
}

and I don't know other method :(

Thanks and Best Regards
Fred Kleinschmidt ha scritto:
Don't top-post. I have moved your reply to where it belongs...
>ma**********@pobox.com ha scritto:
>>Defected wrote:
Hi All,

I have need to write a void function that will merge the contents of two
text file containing chemical elements sorted by atomic number and will
produce a sorted file of binary records. The funcion's parameters will
be three file pointers.
Each text file line contain for example:

11 Sodium Na 22.99
20 Calcium Ca 40.08

The function can assume that one file does not have two copies of the
same element and that the binary output files should have this same
property.
When one of the input files is exhausted, do not forget to copy the
remaining elements of the other input file to the result file.

I have created the function merge that create a binary file with all the
elements, but I don't understand ,how I can make to produce a binary
file without duplicates elements.
You have created a function which should be called "concatenate"...

To merge two files, you read records from both inputs, decide which
record to write to the output, read another file from the appropriate
input, and so on...
>Thanks but how I can make ? I have not idea.

Read a line from file 1 (element A)
Read a line from file 2 (element B)
In a loop:
if elementB is alphabetically before A,
write B
read new element B
else
write A
read new element A
endif
endloop

Remember to add code that handles the end-of-file,
so you don't try to read past it.
Jan 23 '07 #7
In article <Z0******************@twister2.libero.it>
Defected <de**********@gmail.comwrote:
>... I use this:

fscanf(element_1,"%d%s%s%lf",&chemical_1.atomic_n umber,
chemical_1.name,
chemical_1.symbol,
&chemical_1.weight);
while(!feof(element_1)){
...

As a beginning C programmer, you should never (really, never!) use
feof(). (feof() is for intermediate-level C programmers, who need
to distinguish between "read failed because of EOF" from "read
failed because floppy disk has gone bad".)

The fscanf() function has a return value. Use that.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Jan 23 '07 #8

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

Similar topics

2
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give...
5
by: Dave Smithz | last post by:
Hi There, I have a PHP script that sends an email with attachment and works great when provided the path to the file to send. However this file needs to be on the same server as the script. ...
7
by: Joseph | last post by:
Hi, I'm having bit of questions on recursive pointer. I have following code that supports upto 8K files but when i do a file like 12K i get a segment fault. I Know it is in this line of code. ...
3
by: StGo | last post by:
How can i read/write file's custom attributs(like subject,author...) in C#??? Thanks :))
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
13
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming...
1
by: Roy | last post by:
Hi, I have a problem that I have been working with for a while. I need to be able from server side (asp.net) to detect that the file i'm streaming down to the client is saved...
3
by: Shapper | last post by:
Hello, I created a script to upload a file. To determine the file type I am using userPostedFile.ContentType. For example, for a png image I get "image/png". My questions are: 1. Where can...
0
by: troutbum | last post by:
I am experiencing problems when one user has a document open through a share pointing to the web site. I use the dsolefile to read the contents of a particular directory and then display them in a...
0
by: thjwong | last post by:
I'm using WinXP with Microsoft Visual C++ .NET 69462-006-3405781-18776, Microsoft Development Environment 2003 Version 7.1.3088, Microsoft .NET Framework 1.1 Version 1.1.4322 SP1 Most developers...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.