Batch File Problem

This is a discussion on Batch File Problem within the C++ Programming forums, part of the General Programming Boards category; I am calling some batch file commands from my program. The first two ommands say Improper Syntax but the last ...

  1. #1
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200

    Batch File Problem

    I am calling some batch file commands from my program. The first two ommands say Improper Syntax but the last one works.

    Code:
    #include <iostream>
    #include <fstream>
    #include <stdio.h>
    #include <stdlib.h>
    using namespace std;
    
    char Item[3][80];
    
    void Title()
    {
      cout << endl;
      cout << "TrainSim Object Installer" << endl;
      cout << "--------------------------------" << endl << endl;
    }
    
    void Convert(char *RouteName)
    {
      cout << endl << endl;
    
      sprintf(Item[0], "copy *.s \"c:\\Program Files\\Microsoft Games\\Train Simulator\\Routes\\%s\\Shapes\\*.*\"", RouteName);
      sprintf(Item[1], "copy *.sd \"c:\\Program Files\\Microsoft Games\\Train Simulator\\Routes\\%s\\Shapes\\*.*\"", RouteName);
      sprintf(Item[2], "copy *.ace \"c:\\Program Files\\Microsoft Games\\Train Simulator\\Routes\\%s\\Textures\\*.*\"", RouteName);
    }
    
    void CopyShapesAndTextures(char *RouteName)
    {
      system(Item[0]);
      system(Item[1]);
      system(Item[2]);
    }
    
    int main()
    {
      char RouteName[50];
    
      Title();
      cout << "Whats the name of the target route? ";
      cin.get(RouteName, 50).get();
    
      cout << endl;
      cout << RouteName;
    
      Convert(RouteName);
      CopyShapesAndTextures(RouteName);
      //EditREF(RouteName);
    
      cin.get();
      return 0;
    }
    EDIT:
    Also if I input a "RouteName" with a space in it. (My Route) It says cannot find path.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,335
    Well it looks to me like you're trying to sprintf far more than 80 chars into each of your arrays
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Lol, I cant believe I missed that.

    But now, I still cant input a name with a space in it. Any ideas why?

    EDIT:
    I also want to read in a file with the extension .REF
    The thing is I want it to read that file without knowing the name of it. Just open the file with the extension .ref!? Is this possible?

    I tried
    Code:
    ifstream REF("*.ref");
    But didt work

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >But now, I still cant input a name with a space in it. Any ideas why?
    > cin.get(RouteName, 50).get();
    Try getline() instead:
    cin.getline(RouteName,50);

    >The thing is I want it to read that file without knowing the name of it. Just open the file with the extension .ref!? Is this possible?
    You might try piping the output of DIR to a file, and then reading the contents of the file to get the name:
    Code:
    system("dir *.ref >> dir.txt"); //Now dir.txt will contain the directory listing
    Or you could use findfirst() or FindFirstFile() to get the same infomation. See this FAQ entry:
    http://faq.cprogramming.com/cgi-bin/...&id=1044780608

    But perhaps there's a much easier way.
    Last edited by swoopy; 07-19-2004 at 12:07 AM.

  5. #5
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Thanks I'll try all that in the morning

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. read from file problem
    By Martin Kovac in forum C Programming
    Replies: 1
    Last Post: 04-13-2009, 08:33 AM
  2. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  3. File Writing Problem
    By polskash in forum C Programming
    Replies: 3
    Last Post: 02-13-2009, 09:47 AM
  4. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21