Delete first two characters

This is a discussion on Delete first two characters within the C Programming forums, part of the General Programming Boards category; Hello, I am a total newbie at C programming, and programming in general. I am learning though, and I need ...

  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
    Katy, Texas
    Posts
    2,309
    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.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  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, 09:35 AM
  3. Delete Function in Doubly Linked List
    By Dampecram in forum C Programming
    Replies: 5
    Last Post: 11-15-2008, 03: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

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