Thread: Question

  1. #1
    Registered User moonwalker's Avatar
    Join Date
    Jul 2002
    Posts
    282

    Question

    I wrote a program that deletes the TDS EXE and OBJ of a file.
    (I do this because I compile so many programs and I delete them
    and keep only the .C or .CPP files)

    so I wrote another program, called it DUMP. It takes command
    line args. For example, if i want to delete all files (OBJ TDS EXE)
    of DRAGONWAR.CPP, I will simply type DUMP DRAGONWAR
    and it will delete OBJ TDS EXE of DRAGONWAR file.

    Here's the code:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    main(int argc, char *argv[])
    {
    	char one[20] = "DEL " ;
    	char two[20] = "DEL ";
    	char three[20] = "DEL ";
    
    
    	strcat(one, argv[1]);
    	strcat(one, ".tds");
    
    	strcat(two, argv[1]);
    	strcat(two, ".exe");
    
    	strcat(three, argv[1]);
    	strcat(three, ".obj");
    
    	printf("%s\n%s\n%s\n", one, two, three);
    
    	system(one);
    	system(two);
    	system(three);
    
    	
    }
    My problem is that this code is not always working. What could
    the reason be?

  2. #2
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    >> My problem is that this code is not always working

    So when it doesn't work, what's the problem.

    Perhaps it could be because of long filenames. Try enclosing the filename in inverted commas.

  3. #3
    Registered User moonwalker's Avatar
    Join Date
    Jul 2002
    Posts
    282

    oh

    when it doesn't work,

    it simply says

    File Not Found
    File Not Found
    File Not Found

    The files will be manually deleted one by one later by me
    (Thought of using this small program to do that for me)

    Long filenames.... hmm, i am going to test that right away,
    I will compile some programs and delete them and see
    if it is true.

    [edit]
    Yes, it is with the long filenames. I just experimented with
    several files and you're right.
    [/edit]
    Another question: if i send the argument in "", does it
    affect any of my code ?
    Last edited by moonwalker; 08-04-2002 at 06:31 AM.

  4. #4
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    >> if i send the argument in "", does it affect any of my code ?

    Try testing it. I don't think it will affect anything besides the fact that your array would be 2 chars bigger.

  5. #5
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    You should be using the absolute path instead. Like:
    Code:
    strcat(one, "C:\\dir\\");
    strcat(one, argv[1]);
    strcat(one, ".tds");
    ...
    And ofcourse, watch out for buffer overflow!

  6. #6
    Registered User moonwalker's Avatar
    Join Date
    Jul 2002
    Posts
    282

    nope

    nope

    It is sometimes working with "" but sometimes not (same error.
    file not found)

    >You should be using the absolute path instead.
    How do i get the current dir ?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM