Need Advice on starting project in C

Discussion in 'Mac Programming' started by larswik, Mar 14, 2011.

  1. larswik macrumors 68000

    Sep 8, 2006
    I think it was Lee a few months ago that recommended I do some small C projects before moving on. Now that I am taking that Pascal class I want to keep current with my C still.

    I thought of this project that would help save me time I just am having a hard time starting. I have a folder that has hundreds of TV commercials that I have made. I have some MPEG playback units in hotels that play my Visitors channel and I just had to format a drive on one of them. Now I need to dig through the folder manually and find those videos and copy them to a new folder. I have a playlist that sits on these drives that tells the units what items to play.

    I would like to be able to open that list and then go into the folder and copy the video clips from the list to a new folder. Then I can FTP the new videos to the reformatted hard drive.

    I am wondering how I should approach this problem?


  2. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    Step 1: What format is the playlist?

    Step 1 is always "Can I read what I need to read?" and "Can I write what I need to write?". (Step 0 is "What do I need to read and write?", which is answered by the original post.)

    If you don't have documentation for the playlist you intend to read, you will have to decipher it. Deciphering may not succeed, so you couldn't read the playlist even if you wrote the rest of the program.

    You already know you can write what you need to write, because it's just moving or copying files. Even if your program did nothing but read the playlist and produce a series of 'ftp this-file that-file' commands, which you pasted into Terminal, you'd still be able to write lines that say 'ftp this-file that-file'.

    Step 2: Will the program be a command-line tool or a GUI utility?


    Step 3: Break it down.

    Break the problem down into parts and sub-parts until you have solvable pieces. Then solve each piece.
  3. Sander macrumors 6502

    Apr 24, 2008
    Frankly, I wouldn't do this type of thing in C. This looks more suited for a higher level scripting language.
  4. larswik thread starter macrumors 68000

    Sep 8, 2006
    Thanks, The file can be opened up by a text program. The file has an extension .dvc. It is just a text list of the items that the units play. So the list would have 'food1' and the drive would play 'food1.mpg'

    It has nothing to do with the Terminal or FTP. over the years I have 100's of these videos in a folder. I just wanted to open the list which may contain 30 items and have it look through my video folder and make copies of the videos to a new folder. I have no experience with GUI so it is command line based.

  5. balamw Moderator


    Staff Member

    Aug 16, 2005
    New England
    As Sander suggested this might be easier just as a shell script. (C is not the best tool for manipulating strings or files.)

    bash offers a "while read" functionality that would take each line and allow you to further process it.

    e.g. something like (untested):
    while read line
    do oldname="${line}.mpg"
    cp "${oldname}" "${newname}"
    In typical unix fashion, pipe the playlist file in via cat or other redirection.

  6. larswik thread starter macrumors 68000

    Sep 8, 2006
    I see, maybe I will pass on this small project and do it manually.



Share This Page