![]() |
|
#1
|
|||
|
|||
File functionhi friends,
this is the question but i m not continue what shall to proceed and errors occur i m not familiar with c program use of file can u try it please. Write an interactive program that reads three (3) lists of numbers, which are stored in three separate files, and creates one (1) sorted list. Each file should contain not more than 15 numbers. First, you need to create a program that randomly chooses a size (<= 15 numbers) for the list1 and then randomly generates a list of numbers and store them in the file1. Repeat this procedure to select the other two lists (list2 and list3) and stores them in the corresponding files (file2 and file3) for sorting and merging them into one. for example: file1(list 1) 32 12 5 990 1 file2 (list 2) 2000 3 file3 (list 3) 30 6 Output in a separate file: 1 3 5 6 12 30 32 990 2000 code: CPP / C++ / C Code:
Please can anyone try it and whereever require code please insert it and the numbers are not sorted can u try it thks in advance Last edited by LuciWiz : 29-Mar-2007 at 00:07.
Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
|
|||
|
#2
|
|||
|
|||
Re: file functionQuote:
I will give some suggestions. Not everyone would do things this way and in this order, but you might consider the following: First of all, before trying to write and read multiple files and performing a merge/sort, get familiar with use of file I/O in C. 1. The code that you posted will not compile, for a number of reasons. 2. I suggest that you get familiar with file I/O by making a program that will read each and every character from a text file (that you created with a text editor) and print each character to the console. Make sure that it reads exactly what is in the file: no more and no less. 3. Then make a program that reads each and every character from a text file and writes each one to another file. Make absolutely that the end result is that every character from the input file is in the output file, and that the files have exactly the same size. Notes: Every time you do an fopen(), make sure that the file was successfully opened. Print out a message each time. If you are just going to read characters, then fgetc() is appropriate. If you are going to read integers, then fscanf() might be the way to go (at least for starters). If you use fscanf(), make sure that you test each time to make sure that the conversion from file to integer value was successful. You can read up on these functions (and a lot of other good stuff) at sites like this: Standard C I'll get you started with a program that opens a file and counts the total number of bytes in the file: CPP / C++ / C Code:
Output on my Windows XP platform: Code:
After making sure you can read each and every byte, then create a file (with a text editor) that contains the kind of entries your program will be using (integers, I guess). Make sure your program can read every integer from the file and print its value on the screen. Then, start all over with a brand new program that will simply write a few integers to a text file. Look at the file with a text editor after you have run the program. Make absolutely sure that you can write exactly what you intend to write: no less, no more. etc. etc. Approach the problem logically. Make absolutely sure that you implement and test each of the required steps before trying to put them all together. Regards, Dave |
|
#3
|
|||
|
|||
Re: file functionok thanks for help what can i do i want to change the code r it can update in this above code as i posted.
davekw7x he/she given an example one to find the character in the text file but i want to write in those file and read it and after that i want to sorted the integer numbers. can u help me nw. |
|
#4
|
|||
|
|||
Re: file functionQuote:
One thing at at time! Make a program that writes integers to a file. Where do you get the integers? How many integers? That's part of the assigmnent and part of the program. You are going to create a text file. Write one integer on each line. You can write a single integer, n, followed by a newline to stdout with printf("%d\n", n). If you have opened a file for writing, then you write a single integer followed by a newline with fprintf(outfile, "%d\n", n). Then write a program that reads integers from a text file. You can read an integer from stdin with scanf("%d", &n) YOu can read an integer from a text file with fscanf(infile, "%d, &n) Look for examples in your textbook or other course materials. After you know that you can create the files and can read each file, then you need to plan how to do the merge/sort of the three files. But: first things first: make sure you understand how to write and read files. If you write a program that doesn't work as expected, then post the program and ask specific questions about the behavior that you don't understand. Bottom line: I am not going to write the program; you are. Regards, Dave |
Recent GIDBlog
Install Adobe Flash - Without Administrator Rights by LocalTech
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Airport Log program using 3D linked List : problem reading from file | batrsau | C Programming Language | 11 | 29-Feb-2008 07:44 |
| [GIM] gim.h | dsmith | C Programming Language | 0 | 18-Jan-2005 08:48 |
| CD burner wont burn!! | robertli55 | Computer Hardware Forum | 1 | 18-Jun-2004 10:53 |
| Yet another CD burner problem: Lite-On LSC-24082K | Erwin | Computer Hardware Forum | 1 | 22-May-2004 11:28 |
| Revising Script style ?????? | pepee | MySQL / PHP Forum | 4 | 14-Apr-2004 04:59 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The