Thread: file processing

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    3

    file processing

    i am having trouble with file processing.
    for example if a file is like

    123 kevin lin
    423 joe black
    983 peter parker
    877 john smith

    i want to remove the third line( peter parker one) and shift rest of contents up. so that file would go like
    123 kevin lin
    423 jow black
    877 john smith

    please help me in this regard.

  2. #2
    Bob Dole for '08 B0bDole's Avatar
    Join Date
    Sep 2004
    Posts
    618
    what class is this for?
    Hmm

  3. #3
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,090
    One way to do it: Read in the file a line at a time, saving each line in some sort of data structure. Then close the file and open it for writing and write out each line from the data structure. Either during the reading or the writing, identify the line you want to skip, and skip it.

  4. #4
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    the quick,easy,dirty way to do it is this:

    1-open the source file
    2-open (create) a destination file
    <loop>
    3-read a line from the source file
    4-if it's not the line you want to skip, write it to the destination file
    </loop>
    5-close the files
    6-system("copy [destination file] [source file]");
    7-system("del [destination file]");

    like I said, quick, easy, dirty... especially dirty... but for an assignment like this it doesn't seem like it should matter very much unless your teacher specifically told you not to use system commands or they're a real teacher.

    but then again the teachers that give assignments like these don't usually know very much about the language themselves, or they're willing to dumb it down enough for newcommers.

    also, that's assuming you're working in a windows environment. if you're using something else, look up the copy and delete command-line instructions and use them in place of copy and del in steps 6 and 7

    If I were you, I'd look up different ways of doing this, because this is generally not a good way to go about doing it for security reasons, among other things... "security" seems to be a big buzzword around the software industry... I write a small program for somebody to calculate weight on the moon, and they ask me if it's "secure" enough and ask questions about it's "vulnerability to attack from hackers, spyware, and viruses" wtf...
    Last edited by major_small; 12-01-2004 at 09:16 AM.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  5. #5
    Registered User
    Join Date
    Dec 2004
    Posts
    3
    i am using windows and visual c++ compiler. isnt there any easy way to do so. how can i rename the modified destination file to source file and delete the source file.

  6. #6
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    I just told you the easy way... other ways are shifting bits in the file stream, and going more specifically into windows programming, which both seem a little advanced for where you are now...
    Last edited by major_small; 12-01-2004 at 12:02 PM.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  7. #7
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    I write a small program for somebody to calculate weight on the moon, and they ask me if it's "secure" enough and ask questions about it's "vulnerability to attack from hackers, spyware, and viruses" wtf...
    You mean one of those 3-liners? Input weight, divide by 6 and spit out the answer?... Is this person a developer him/herself?

    >> isnt there any easy way to do so.
    If there was an easier way, it would have been mentioned.

    >>how can i rename the modified destination file to source file and delete the source file.
    Read major_small's post, idijut.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  8. #8
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Quote Originally Posted by Hunter2
    You mean one of those 3-liners? Input weight, divide by 6 and spit out the answer?... Is this person a developer him/herself?
    exactly what I mean... and no, thankfully they weren't a developer... if they were I would have to tear into them for that...

    edit: actually, there was a semi-infinite loop involved... one of those "enter 0 to end the program" types of deals...
    Last edited by major_small; 12-01-2004 at 12:04 PM. Reason: detail
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  9. #9
    Registered User
    Join Date
    Dec 2004
    Posts
    3
    i,m working in windows, but his system command isnt working
    system("copy [destination file] [source file]");
    system("del [destination file]");
    can u plz let me know the exact code to copy and delete files.

  10. #10
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >how can i rename the modified destination file to source file and delete the source file.
    One way:
    Code:
       remove("source_file.txt");
       rename("modified_file.txt","source_file.txt");
    Or:
    Code:
       system("delete source_file.txt");
       system("copy modified_file.txt source_file.txt");

  11. #11
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    i,m working in windows, but his system command isnt working
    system("copy [destination file] [source file]");
    system("del [destination file]");
    can u plz let me know the exact code to copy and delete files.
    Gee, I wonder why Look, copy and paste will rarely if ever work. Figure out what the person's saying, learn it, understand it, and then write it. You asked how to copy and delete files; he told you HOW to copy and delete. Since you neglected to tell him the filenames of the files you're trying to copy and delete, he put [destination file] and [source file] as placeholders. By the thunderbolts of Zeus, he gave you AS CLOSE TO THE FRIGGIN EXACT CODE AS POSSIBLE!

    Quote Originally Posted by Thantos
    I smite you in the name of intelligence. May your ignorance and refusal to listen be banished to the Netherworld. Be gone heathen!
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  12. #12
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Quote Originally Posted by Hunter2
    By the thunderbolts of Zeus, he gave you AS CLOSE TO THE FRIGGIN EXACT CODE AS POSSIBLE!
    haha... you just made me laugh in the middle of a javascript class... that's now just as classic as Thantos' quote
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File Writing Problem
    By polskash in forum C Programming
    Replies: 3
    Last Post: 02-13-2009, 10:47 AM
  2. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  3. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  4. file processing updating record error
    By uuser in forum C Programming
    Replies: 2
    Last Post: 04-27-2003, 12:13 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM