Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a C++ Expert!

Join 244,307 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 791 people online right now. Registration is fast and FREE... Join Now!




Merge data from two text files

 
Reply to this topicStart new topic

Merge data from two text files, Help is needed, Please

benchCUB
8 Jan, 2009 - 07:55 AM
Post #1

New D.I.C Head
*

Joined: 6 Jan, 2009
Posts: 5

so far i have learnt reading 1 text file only.

I hav a class exercise that ask to combine the data from two text files. I don't have any idea how to merge data from two text files as i have just learnt C. This is in C

textA.txt

0978 YL1 Clark Kent Joe
0891 YL2 Klum Heidi
1234 YL1 Ardent Keith

textB.txt

0867 YL3 Underwood Carrie Ross
0673 YL4 Fisher Mark Rob

the printout that must be displayed

0978 YL1 Clark Kent Joe
0867 YL3 Underwood Carrie
0891 YL2 Klum Heidi
0673 YL4 Fisher Mark Rob
1234 YL1 Ardent Keith


my structure looks like this
CODE


typedef struct list
{
         char id[9];
         char yr[10];
         char fname[10];
         char lname[10];
}LIST;

FILE * plist;


This post has been edited by Jayman: 8 Jan, 2009 - 08:21 AM

User is offlineProfile CardPM
+Quote Post


Jayman
RE: Merge Data From Two Text Files
8 Jan, 2009 - 08:22 AM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 8,063



Thanked: 159 times
Dream Kudos: 500
Expert In: Everything

My Contributions
Topic renamed to be more descriptive of the problem.
User is offlineProfile CardPM
+Quote Post

KYA
RE: Merge Data From Two Text Files
8 Jan, 2009 - 08:34 AM
Post #3

#include <nerd.h>
Group Icon

Joined: 14 Sep, 2007
Posts: 9,508



Thanked: 363 times
Dream Kudos: 2550
Expert In: C, C++, Java

My Contributions
I can offer several routes to solve the problem. Is the ordering of data important? If not, why not just read in file B and then append it to file A?
User is offlineProfile CardPM
+Quote Post

benchCUB
RE: Merge Data From Two Text Files
8 Jan, 2009 - 09:49 AM
Post #4

New D.I.C Head
*

Joined: 6 Jan, 2009
Posts: 5

QUOTE(KYA @ 8 Jan, 2009 - 08:34 AM) *

I can offer several routes to solve the problem. Is the ordering of data important? If not, why not just read in file B and then append it to file A?


i actually have to sort it alpabetically by last name

but right now i need to learn how to merge so i can start
i hope u can show me some starting codes
User is offlineProfile CardPM
+Quote Post

KYA
RE: Merge Data From Two Text Files
8 Jan, 2009 - 10:03 AM
Post #5

#include <nerd.h>
Group Icon

Joined: 14 Sep, 2007
Posts: 9,508



Thanked: 363 times
Dream Kudos: 2550
Expert In: C, C++, Java

My Contributions
CODE

//read in structure from Text File B
//write said structure to Text file A


You can successfully read and write from files right? Then you already have all the tools you need. If you need to create a third file then read in both A and B and write them. Then you can sort Text File C.
User is offlineProfile CardPM
+Quote Post

benchCUB
RE: Merge Data From Two Text Files
8 Jan, 2009 - 10:58 AM
Post #6

New D.I.C Head
*

Joined: 6 Jan, 2009
Posts: 5

QUOTE(KYA @ 8 Jan, 2009 - 10:03 AM) *

CODE

//read in structure from Text File B
//write said structure to Text file A


You can successfully read and write from files right? Then you already have all the tools you need. If you need to create a third file then read in both A and B and write them. Then you can sort Text File C.


pls don't get annoyed for asking so much questions..i am new to C so i need guidance.

I tried to read both text files but what is printed out is only from one text file
my questions are

1. is it possible to read two text files and how?

2. can i sort if i only append to text file A what has been read from text file B?

3. or i really need to read both files and write them before i can do sort?

thanks, i appreaciate everything

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic

Time is now: 7/4/09 06:47PM

Live C++ Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month