Question on C programming

lookouthere

Senior member
May 23, 2003
552
0
0
I have a filelist in a file but I need to call each file name in that filelist. I should be using arrays and pointers right? After I call that each file, I need to change all the spaces to tabs. I have to do looping for each files? Can anyone suggest on how to do this? like a skeleton code. By the way, each of this file are matrix/tables.
Right now I have this only.

#include <stdio.h>
#define NULL 0

main(int argc, char *argv[])
{
FILE *fpt;
if ((fpt=fopen(argv[], "r")) == NULL)
printf("\nERROR-Cannot open the designated file\n);
else{
do

fclose(fpt);
}
}



Also, after this part done, I need to combine all the matrix/table together in 3 different part. For example, table1-a and table1-b need to combine to table1. table2-a and table2-b need to combine to table2. How should I do that?
thanks



---------------------------------------------------------------------
Given the vagueness and lack of effort put into the OP, only psuedo code will be allowed to be posted to provide assistance if at all.


Senior Anandtech Moderator
Common Courtesy
 

erwos

Diamond Member
Apr 7, 2005
4,778
0
76
Is "use Perl" a valid answer?

This looks _suspiciously_ like a school assignment.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
You're going to have to open the file, and read each of the filenames into an array of characters. They're either separated by newlines or some separator character. If it's newlines you can just read line by line. If it's a separator character then you'll need to read in the whole line and parse it out.

For a task like this I would start with the outer loop and drill in. You need to verify that the file exists, open it, read the filenames into your buffers (probably an array of arrays of characters), and then pass the list of names to a function that controls the rest of the processing. Take a stab at that, and post back with more specific questions. They always get more helpful replies than "How do I do this big thing I have to do?"
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
You're also much less likely to fail the class if you do as much of the work on your own as you can.

The problems on the midterm / final probably won't match any of these assignments, so if you just memorize the answers you won't have any idea how to make even slight changes.
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Originally posted by: lookouthere
This is for a job but I have never done like this before in school =s

If you learned any type of programming in school; then the concepts should be clear. Prototype/psuedo code what is needed first

 

Gamingphreek

Lifer
Mar 31, 2003
11,679
0
81
Originally posted by: lookouthere
This is for a job but I have never done like this before in school =s

You have never done file I/O in school??

Well, I sincerely hope that we are not providing answers for school work - but I'll trust you with this one.

First thing you need to do is run a check to make sure the hard coded batch file exists. If it doesn't, it should return a 0 or NULL (in which case the program should exit).

If that passes, open the file with a FILE * (Make sure to call malloc() (or new if C++) and allocate space for the pointer.

Once in the file, you will want to read everything into a buffer so you limit yourself to 1 file access. So you'll need to read until you hit the delimiter for the particular file name. Those will need to be read into a char*. That character array also needs to be allocated dynamically.

Once you have read in each file name, you'll need to increment through your char array and test to make sure each file name exists before opening it.

From here, you were not clear on what file type you are reading in. You say there are matrices and tables, but you could arrange a .txt file to look like that.

At any rate, depending on the size of the file, you either create a second buffer (For large files) and change all your spaces to tabs or whatever, or you use fprintf() to edit the file directly.

At the end make sure to call free() and close each file.

As for the second part, again trusting this isn't a school assignment, is also unclear. How do you mean combine the tables/matrices? Add the values together? Append them on the end of the existing "matrix"?

-Kevin

Edit: For anyone here to provide any pseudo code or sample source code, you are going to have to show that you have made some strides on this yourself. Writing the main function to open 1 file and saying "Now what?" is not enough.
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Originally posted by: Gamingphreek
Edit: For anyone here to provide any pseudo code or sample source code, you are going to have to show that you have made some strides on this yourself. Writing the main function to open 1 file and saying "Now what?" is not enough.



Given the vagueness and lack of effort put into the OP, only psuedo code will be allowed to be posted to provide assistance if at all.


Senior Anandtech Moderator
Common Courtesy
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |