Thread: Simple c++ program

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    3

    Simple c++ program

    I am trying to figure out how to make a program perform the following funtion "cpc -B *.cpc -O 1" where 1 is the directory... What that function does is converts .cpc files into .tif files... It would be ran out of my c:\cpc folder and I would like to be able to choose a directory to convert the new .tifs in to.... Can anyone recommend the best way of going about this? I am very new to c++ and trying to read all I can..

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Are you looking for a program that already exists?
    http://www.google.com/search?q=cpc+tif

    If you are planning on writing one yourself, I think it would be a bit much for a beginner.
    What that function does is converts .cpc files into .tif files
    Can you write it yourself?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Jun 2006
    Posts
    3
    I'm sorry for explaining it bad.. I already have the program that converts them.. But as it is I have to type out cpc -B *.cpc -O 1 every time, and I want to make it to where all I have to do is double-click an icon on my desktop and have it pop up and ask something to the effect of "what directory would you like to save your files in?" and have it make one...

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    FAQ > How do I... (Level 1) > Get a line of text from the user/keyboard (C)
    FAQ > How do I... (Level 2) > Run a program from within a program

    Put together as something like this.
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    int main(void)
    {
       char path[FILENAME_MAX];
       fputs("path? ", stdout);
       fflush(stdout);
       if (fgets(path, sizeof path, stdin))
       {
          char command[sizeof path + 30];
          char *newline = strchr(path, '\n');
          if (newline != NULL)
          {
             *newline = '\0';
          }
          sprintf(command, "cpc -B *.cpc -O %s", path);
          puts(command); /* to see the created command line */
          system(command);
       }
       return 0;
    }
    Example:
    path? c:\
    cpc -B *.cpc -O c:\
    Like that?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Registered User
    Join Date
    Jun 2006
    Posts
    3
    Yes, exactly like that... Thank you very much.. Not only will this ease my work but now I have something to look over, study, and learn from... Really appreciate it..

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    You can normally achieve that with a little bit of batch file programming.
    It's very easy if your shell is bash though.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with a very simple program
    By htdefiant in forum C++ Programming
    Replies: 13
    Last Post: 08-14-2007, 01:27 PM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. [Help] Simple Array/Pointer Program
    By sandwater in forum C Programming
    Replies: 3
    Last Post: 03-30-2007, 02:42 PM
  4. simple silly program
    By verbity in forum C Programming
    Replies: 5
    Last Post: 12-19-2006, 06:06 PM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM