473,657 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.d at", "wb");
element_1 = fopen("text1.tx t", "rb");

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_1)){
fwrite(&chemica l, sizeof(chemical _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);

}
fclose(element_ 1);
element_2 = fopen("text2.tx t", "rb");

fscanf(element_ 2,"%d%s%s%lf",& chemical_2.atom ic_number,
chemical_2.name ,
chemical_2.symb ol,
&chemical_2.wei ght);
while(!feof(ele ment_2)){
fwrite(&chemica l, sizeof(chemical _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);
fclose(element_ 2);
fclose(element) ;

}
Thanks
Jan 23 '07 #1
7 2113

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...@po box.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**********@po box.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**********@po box.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.htm l>
<http://cfaj.freeshell. org/google/ (taming google)
<http://members.fortune city.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.atom ic_number,
chemical_1.name ,
chemical_1.symb ol,
&chemical_1.wei ght);
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);
}

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**********@po box.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**********@g mail.comwrote:
>... I use this:

fscanf(element _1,"%d%s%s%lf", &chemical_1.ato mic_number,
chemical_1.name ,
chemical_1.symb ol,
&chemical_1.wei ght);
while(!feof(el ement_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
3921
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 them a caption, storing the caption and filename in a text file. It's a bit buggy when removing the photos and captions from the file, and also in displaying them on the delete page. you can see it in action at www.4am.com.au/gallery/upload.php...
5
5451
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. I want to develop a webpage where people can send attachments that are stored on their local PC.
7
3529
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. How do i make the last pointer in the indirect sector that has another level of indirect pointer, and be defined recursively to support infinite large files? -code-
3
26259
by: StGo | last post by:
How can i read/write file's custom attributs(like subject,author...) in C#??? Thanks :))
0
3931
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. It is almost like it is trying to implement it's own COM interfaces... below is the header, and a link to the dll+code: Zip file with header, example, and DLL:...
13
4297
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 that this is suppossed to end up as a component for others to use, and therefore I do NOT have access to their global.cs::Session_End() how do I cleanup files that were uploaded -- but obviously left stranded when the users aborted/gave up writting...
1
5377
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 completely/succsessfully on the client's computer before updating some metadata on the server (file downloaded date for instance) However, All examples i have tried, and all examples I have found that other people says works - doesn't work for me :-(
3
3161
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 I find a list of all the types which can be returned? For example, if it is a Word document will it return "document/doc".
0
2560
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 datalist. When the next user selects trys to run the page, the page fails and I get a generic error message from the stack trace. I am assuming that the document properties cannot be read when a file is open, but it worked well in asp. ...
0
2026
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 said to me that they have no problem doing that, but the following project file is said to be corrupted while opening in the IDE, it is the project file of NT xemacs BETA 21.5.24, http://ftp.xemacs.org/pub/beta/xemacs-21.5.24.tar.gz (under the...
0
8310
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8826
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
7330
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6166
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4155
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4306
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.