Hello. For the last 5 days, I begun to learn C (with K&R alongside with "C primer plus" for that little bit of extra explanation).
I know it's a bit early to ask questions, but I try to push myself.
So I decided to write a program in C that takes all of my .wav files in my dir and make them mp3 with tags. So far, I have this:
Code:
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
void remove_enter( char *s ) // function to remove enter from stdin
{
s[strcspn( s, "\n" )] = '\0';
}
int main()
{
char artist[40];
char album[40];
char genre[20];
char year[4];
printf("Enter artist name:\n"); // input name, move to array, remove \n
fgets(artist, 256, stdin);
remove_enter(artist);
printf("Enter album name:\n");
fgets(album, 256, stdin);
remove_enter(album);
printf("Enter year:\n");
fgets(year, 256, stdin);
remove_enter(year);
printf("Enter genre:\n");
fgets(genre, 256, stdin);
remove_enter(genre);
char argv[512]; // create array to pass lame switches
snprintf(argv, 512, "/usr/local/bin/lame --ta %s --tl %s --ty %s --tg %s *.wav", artist, album, year, genre); // lame to array
system(argv); // pipe exec to system
return 0;
}
The "problem" is that it excecutes only if there is only 1 wav file inside the directory. It is more than obvious that I must read my @ss off and I'm excited about that.
Can I ask for some pointers for what do I have to look for to be able to excecute this program for a number of wav files (>1)? (not a solution, just for a more general direction)
I also would love some criticism about how correct is the code. (again, I know it's not much
).
Thank you.