Hi, I'm trying to make a program to list files in a dir specified by a user, find all video files with magic and convert them so that the psp will play them. However I'm trying to pass the directory and file name to a function and in the function add them together with sprintf, but it's not working. No idea what's wrong with it, I'd be extremely grateful for any help. Here's the code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <magic.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
int mencoder_move() {
return 0;
}
int assesment(char *file_from_dir, const char *dir_to_conv) {
char *full_path;
sprintf(full_path,"combined = %s%s\n", dir_to_conv, file_from_dir);
/* strcat(full_path, file_from_dir);
printf("%s\n %s\n %s\n", full_path, file_from_dir, dir_to_conv);
*/
return 0;
}
int magic_database(void) {
magic_t magic_cookie;
magic_cookie = magic_open(MAGIC_MIME);
if (magic_cookie == NULL) {
printf("unable to initialize magic library\n");
return 1;
}
printf("Loading default magic database\n");
if (magic_load(magic_cookie, NULL) != 0) {
printf("cannot load magic database - %s\n", magic_error(magic_cookie));
magic_close(magic_cookie);
return 1;
}
return 0;
}
int main(int argc, char *argv[])
{
/*find directory needed to convert*/
if (argc != 3) {
printf("> Howto: %s <directory to convert> <directory to move converted files to>\n", argv[0]);
return 1;
}
/*make directory to transfer files to*/
if (mkdir(argv[2], S_IRWXU) != 0) {
printf("Could not create directory.\n");
struct stat st;
if (stat(argv[2], &st) == 0)
printf("%s already exists.\n", argv[2]);
else
return 1;
}
magic_database();
const char *user_dir;
user_dir = argv[1];
printf("Converting video files in: %s\n", user_dir);
DIR *dir_convert;
struct dirent *listing;
dir_convert = opendir(user_dir);
/*listing dir*/
if (dir_convert != NULL) {
while ((listing = readdir(dir_convert))) {
assesment(listing->d_name, user_dir);
}
(void) closedir (dir_convert);
}
else
perror("Could not open the directory");
return 0;
}