Hi, I'm trying to write a program to archive, basicaly concatenate some files from a folder. The names of the files are obtained from the file_ls file which contains the result you get when you run ls -la in linux. It's lines of text like this:

drwxr----- 13 slobo slobo 2048 2009-01-16 22:44 ..
-rw-r--r-- 1 slobo slobo 1646 2008-12-15 09:42 usermap.txt

The program should concatenate the files upon inputing the following command:

load file_ls usermap.txt archivename

So it looks into file_ls, finds all the files, then concatenates their content and writes it in the file archivename. The program should also write a header for each of the files, before the content of the file itself, like the tar specifications, that's where I'm going to use usermap.txt. But I'm not worrying about that now, first I'm trying to get it to just concatenate the files ie add their content to the archivename.

My code looks like this :

#define MAX 1000
FILE *s, *d;
void copy( FILE *d, FILE *s)
	int c;
	char zone[MAX];
	while((c=fread(zone, 1, MAX, s))>0)
		fwrite(zone, 1, c, d);

void load(char *archivename)
	char *x;
	long len;
	FILE* pf = fopen("file_ls", "rb");
	fseek(pf, 0, SEEK_END);
	fseek(pf, 0, SEEK_SET);
	fread(x, 1, len, pf);
	char *t, *u;
	t=strtok(x, "\n");
			u=strchr(t, ':');
			printf("This is the name of a file from file_ls \n");
			s = fopen(u, "r");
			d = fopen(archivename, "a+");
	t=strtok(NULL, "\n");

int main(){
	char *command, *archivename, *filename, *p;
	int i, j, n, ok=0;
	fgets(command, 100, stdin);
	p="load file_ls usermap.txt";
	if(strncmp(command, p, n )==0)
	printf("The name of the archive is: \n");
	printf("  Launching load!!!");
	return 0;

I need some help with this. It compiles ok, but it doesn't work, doesn't copy anything. I think the copy function is alright, because it worked in other, simpler programs. Any help would be appreciated.

If you can change the content of the input file, change the ls command to report file names only. That would greatly simplify your program.

This article has been dead for over six months. Start a new discussion instead.