Thread: Delete first two characters

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    18

    Delete first two characters

    Hello, I am a total newbie at C programming, and programming in general. I am learning though, and I need help with deleting characters from a file name. What I am trying to do is have a program that looks at a file, and renames it by deleting the first, lets say two, letters in it. So lets say the file name was testfile.exe, I would like it to be renamed to stfile.exe. What I was thinking was that I would have to use a command that gets the file name and then another command that deletes the first two letters, and then another that pastes that back using the rename() function. Would this be a good way to go at it? And if so, how could I erase the first x characters in a word?

    Thank you =]

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    An easier way would be to call rename(), passing the pointer to the current name as the first parm, and passing another pointer, to the same old name, but incremented by 2 bytes, as the second parm.
    Mainframe assembler programmer by trade. C coder when I can.

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    18
    Quote Originally Posted by Dino View Post
    An easier way would be to call rename(), passing the pointer to the current name as the first parm, and passing another pointer, to the same old name, but incremented by 2 bytes, as the second parm.
    Thank you very much, I was not aware that that is possible, but I will definitely look into that. I got exactly the type of answer I wanted. All you did was point me in the right direction, which is exactly what I wanted. Thank you very much =D

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. delete functor
    By KIBO in forum C++ Programming
    Replies: 2
    Last Post: 05-08-2009, 08:25 AM
  2. C Delete opened file
    By gidion in forum C Programming
    Replies: 25
    Last Post: 12-04-2008, 10:35 AM
  3. Delete Function in Doubly Linked List
    By Dampecram in forum C Programming
    Replies: 5
    Last Post: 11-15-2008, 04:30 PM
  4. deleting characters
    By scrasnu in forum C Programming
    Replies: 5
    Last Post: 09-01-2008, 09:21 AM
  5. Problem need help
    By Srpurdy in forum C++ Programming
    Replies: 1
    Last Post: 07-24-2002, 12:45 PM