// 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 int main(void) { int c,i,n; //c is the getchar() checker //i is the amount of lines deleted counter //n is the '\n' counter(used to show what line number has been deleted) FILE *fp; int countgoodlines; fp = fopen("tracklist.txt","w"); //file tracklist.txt should not exist c = i = n = countgoodlines = 0; while((c = getchar()) != EOF) { if(c == '\n') ++n; // if c is a newline, increment newline counter, (to display line deleted) // check to see if this line will be ignored from file (tracklist.txt) if(c == '#') { printf("Line %d has been deleted\n",n); ++i; c='\n'; //can I set c = '\n' and the (while(c=getchar()).. will goto the next line?) } if(c != '#' && c != '\n') { //here I want to copy over the good lines, this fprintf is just //a temporary placeholder for the eventual code I will use to //transfer over the actual line fprintf(fp,"This is a good line%d.\n",countgoodlines++); } } //display the amount lines that were not written to the new file (tracklist.txt) printf("%d lines have been deleted.\n",i); fclose(fp); return 0; }