All pastes #419250 Raw Edit

m3u-to-tracklist.txt

public text v1 · immutable
·published 2007-04-01 04:58 UTC
rendered paste body
// m3u to tracklist.txt
// I rip cd's and i create .m3u files that usually look like
// #EXTM3u
// #EXTsomething blahblahbalh
// 01 - artist - track
// #EXTsomething blablabalbla
//
// so I wrote this application to read the .m3u, create a .tracklist.txt 
// and only copy over the lines not starting with #


#include<stdio.h>

int main()
{
	int c,lineskilled,n;  
	//c is the getchar() checker
	//lineskilled is the amount of lines deleted counter
	//n is the '\n' counter(used to show what line number has been deleted)
	FILE *fp;
	

	fp = fopen("/home/greg/Desktop/tracklist.txt","w");
	
	if(fp == NULL)
		printf("Error, could not open tracklist.txt for writing.");
	//file tracklist.txt should not exist

	c = lineskilled = n = 0;


	while((c = getchar()) != EOF)
	{
		

	
		if(c == '#')
		{
			printf("Line %d has been deleted\n",n++);
			++lineskilled;


			while((c = getchar()) != '\n' && c != EOF);
				
			//for( ; ; c=getchar())
			//	if(c == '\n')
			//		break;
			//		for(i=0;i<10;--i)
					

		}

		else if(c != '#')
		{
			//here I  copy over the good lines

			for(;;c=getchar())
			{	//while the character is not a newline continue printing to tracklist.txt
				if(c != '\n')
					fprintf(fp,"%c",c);
				else
					break;
			}
			fprintf(fp,"\n");
			++n; // increment the newline character counter
		}
		
	}
	
	//display the amount lines that were not written to the new file (tracklist.txt)
	printf("%d lines have been deleted.\n",lineskilled);
	
	fclose(fp);

	return 0;
}