DaemonForums  

Go Back   DaemonForums > Miscellaneous > Programming

Programming C, bash, Python, Perl, PHP, Java, you name it.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1   (View Single Post)  
Old 11th November 2011
Daffy Daffy is offline
Fdisk Soldier
 
Join Date: Jun 2010
Posts: 73
Default First program in C

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.
Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
DragonFly BSD disklabel program changes. J65nko News 0 18th February 2010 01:59 AM
Can't install program guitarscn OpenBSD General 3 31st August 2009 08:40 PM
How to learn to program under BSD? Sunnz Programming 5 24th December 2008 11:45 PM
Learning how to program Solaris_Delta Programming 9 24th December 2008 07:58 PM
run linux's program johnzlly OpenBSD General 38 8th November 2008 12:10 PM


All times are GMT. The time now is 01:01 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick