Thread: How to write back to a temp file keeping the orginal or modifed org file format?

  1. #16
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    I'd like to see what happens with this "program" when presented with a file where the first character is a comma.
    That's not a problem, it's a feature.

  2. #17
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by Salem View Post
    I think you're wasting your time Hodor with this shrub - though it is entertaining

    He continues to post rubbish, but never listens to any critisism.

    > infile.seekg(position-2, std::ios::beg);
    I'd like to see what happens with this "program" when presented with a file where the first character is a comma.
    what he did is not criticism.
    Quote Originally Posted by Hodor View Post
    I might look again once it is formatted in a readable manner
    their is not one damn thing wrong with how I indented my code in order for someone to read it.

    You have proven him wrong by pointing out something I have not even gotten to yet.

    Nor is that a realistic test. Who starts a sentence with a comma, and where do you even see that I said this is a completed program?

    Nor it is written in the comments up top to do such a thing. totally unrealistic on your part.

    Never the less I was working on how to save the text in another file in the same or modified text that I have not done that part yet. I jumped to that step because I felt like it, as it seems you must know.

    Quote Originally Posted by Hodor View Post
    And why did you want to use the numbers? To highlight even further your stupidity?
    and this is the behavior you love to see coming out of someone, you're just an enabler to his childish behavior in name calling because he did not get the response out of me he was looking for you he regressed into a childish state of mind and started his naming calling.

    And you pat him on his head for it and tell him hes a good boy for his behavior. though with your childish name calling I can see that you're no better then he is, "with this shrub"
    just two peas in a pod feeding each other.

    I'm sure by Hodor standards this too is poorly formatted
    Code:
    #include <linux/fs.h>        /* file_operations */
    #include <linux/miscdevice.h>
    #include <linux/mm.h>        /* VM_IO */
    #include <linux/module.h>
    #include <linux/uaccess.h>
    
    static unsigned char __HOSTLINK__[4 * PAGE_SIZE] __aligned(PAGE_SIZE);
    
    static int arc_hl_mmap(struct file *fp, struct vm_area_struct *vma)
    {
        vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
    
        if (io_remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
                       vma->vm_end - vma->vm_start,
                       vma->vm_page_prot)) {
            pr_warn("Hostlink buffer mmap ERROR\n");
            return -EAGAIN;
        }
        return 0;
    }
    
    static long arc_hl_ioctl(struct file *file, unsigned int cmd,
                unsigned long arg)
    {
        /* we only support, returning the physical addr to mmap in user space */
        put_user((unsigned int)__HOSTLINK__, (int __user *)arg);
        return 0;
    }
    
    static const struct file_operations arc_hl_fops = {
        .unlocked_ioctl    = arc_hl_ioctl,
        .mmap        = arc_hl_mmap,
    };
    
    static struct miscdevice arc_hl_dev = {
        .minor    = MISC_DYNAMIC_MINOR,
        .name    = "hostlink",
        .fops    = &arc_hl_fops
    };
    
    static int __init arc_hl_init(void)
    {
        pr_info("ARC Hostlink driver mmap at 0x%p\n", __HOSTLINK__);
        return misc_register(&arc_hl_dev);
    }
    module_init(arc_hl_init);
    Last edited by userxbw; 11-15-2017 at 01:02 PM.

  3. #18
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Normally the process for this is to open the file you want to change for reading. Then you open a new file for writing, make your changes, writing to the new file only. When you are all done, you can close and remove the old file, and close and rename the new file so that it has the same name as the old one.

    In newer versions of C++ there is a filesystem library that does much of what you need to do in an object-oriented manner.
    Filesystem library - cppreference.com
    So to delete "my/path/to/file.txt" you would have to turn that into a path object and then call remove(). It is a similar process to rename.

    If your compiler is a little older, then you ought to use the C library to remove and rename.
    their is not one damn thing wrong with how I indented my code in order for someone to read it.
    Personally, I think it could have been done a little better. My one real requirement for indenting, is that spacing is consistent - which it looks like you have done - and closing braces are on their own lines - which you haven't done, it looks like. While what you have posted in that regard is not perfect, I'm cutting you a break. Mostly because what you asked about is a pretty general question.

    Nor is that a realistic test. Who starts a sentence with a comma, and
    Well, programmers are paranoid that users aren't cooperative. It could easily just happen.

    where do you even see that I said this is a completed program?
    Nowhere. Importantly, the opportunity we have to tell you about the problem is now. It isn't a demand to immediately address it. But who knows when, if at any point, you wanted to be informed about that problem.

  4. #19
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > Nor is that a realistic test. Who starts a sentence with a comma, and
    Any passing random hacker who realises that the goofball programmer has left a way in for them to exploit your system.
    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.

  5. #20
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by whiteflags View Post
    Normally the process for this is to open the file you want to change for reading. Then you open a new file for writing, make your changes, writing to the new file only. When you are all done, you can close and remove the old file, and close and rename the new file so that it has the same name as the old one.

    In newer versions of C++ there is a filesystem library that does much of what you need to do in an object-oriented manner.
    Filesystem library - cppreference.com
    So to delete "my/path/to/file.txt" you would have to turn that into a path object and then call remove(). It is a similar process to rename.

    If your compiler is a little older, then you ought to use the C library to remove and rename.

    that part is already in there just commented out until I get further into this program so not to have to keep rewriting a test file.
    thanks for that input
    Code:
      infile.close();    temp.close();
        //remove(argv[1]);
        //rename("temp.txt", argv[1]);
       //std::ifstream tempfile(argv[1]);
    
        std::ifstream tempfile("temp.txt");



    Quote Originally Posted by whiteflags View Post
    Personally, I think it could have been done a little better. My one real requirement for indenting, is that spacing is consistent - which it looks like you have done - and closing braces are on their own lines - which you haven't done, it looks like. While what you have posted in that regard is not perfect

    can someone say OCPD?

    Quote Originally Posted by whiteflags View Post
    , I'm cutting you a break.

    who made you my lord and master when it comes to where I put my brackets and how I indent my code (or for anything for that matter )?
    Quote Originally Posted by whiteflags View Post
    Mostly because what you asked about is a pretty general question.


    To say you are not going to help someone with their code on the basis of how they indented and placed their brackets is arrogant. That is not helping anyone learn how to code to make the program do what it is intended to do.

    when are you people going to get it into your heads coding indentation and bracket placement is personal preference,and not a requirement. If and when you get a company you then can dictate to them how you want the code written to your specifications or you will not pay them for their two weeks of work.

    If you have which you should do, is go look at production code and go see all of the different manners in which it is written.

    Then if you still feel that need to judge someone that you found did not indent their code or place a bracket in a place to your liking then you personally e mail them and beg for a response just to see what they tell you as well about your requirements for bracket placements and indentations. so you can see you're going to get a like response that you got from me on that matter.


    Quote Originally Posted by whiteflags View Post
    Well, programmers are paranoid that users aren't cooperative. It could easily just happen.
    no that is just him being arrogant and you showing your true colors. What did that comment in the upper part of my code state to do? no where is it a requirement to code for such a thing as well, and that final part to check for missing spaces between words. hahaha that is a big data base that would be needed for such a thing. Will I code for that? NO!
    Quote Originally Posted by whiteflags View Post
    Well, programmers are paranoid
    I'm finding that to be an understatement for some
    Quote Originally Posted by whiteflags View Post
    Nowhere. Importantly, the opportunity we have to tell you about the problem is now. It isn't a demand to immediately address it. But who knows when, if at any point, you wanted to be informed about that problem.
    what problem are you referring to? just referring to a situation when you have mentioned many "problems" that seem to be eating away at your psyche then to vaguely state " the problem" .

    that whole paragraph is vaguely posed.
    Last edited by userxbw; 11-15-2017 at 02:25 PM.

  6. #21
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by Salem View Post
    > Nor is that a realistic test. Who starts a sentence with a comma, and
    Any passing random hacker who realises that the goofball programmer has left a way in for them to exploit your system.
    yeah ok I can really see that happening with this program I am writing just to see what I can see. yeah I am almost ready to ship it off to Microsoft here in a few days.. I even got the box to put it in already.

  7. #22
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    that part is already in there just commented out until I get further into this program so not to have to keep rewriting a test file.
    thanks for that input
    Your welcome. I just wanted to explain what to do in general because the seeking around the file isn't really helping you do it right.

    who made you my lord and master when it comes to where I put my brackets and how I indent my code (or for anything for that matter )?
    I'm giving you my opinion. You are welcome to ignore it if you like.

    Why is your attitude so bad toward criticism in general? It really seems like whenever the thread shifts in a direction you didn't plan on, any other comments we make other than what you strictly want to talk about, you treat it like a personal attack.

    what problem are you referring to? just referring to a situation when you have mentioned many "problems" that seem to be eating away at your psyche then to vaguely state " the problem" .

    that whole paragraph is vaguely posed.
    The only problem being discussed is the one mentioned in post 15, because that is what you were talking about at the time. I thought it would be clear in context, because I depended on you to remember what you were talking about.

  8. #23
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    One can only imagine the hissy fits when user-unexploded-bomb gets their first code review at their first job.
    Might just be their last code review.
    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.

  9. #24
    Guest
    Guest
    Quote Originally Posted by userxbw
    when are you people going to get it into your heads coding indentation and bracket placement is personal preference
    But there needs to be a system to it, and some styles are clearly more readable than others. And programming is an area where order is of particular importance. The analogous situation here would be that you're a writer and want others to give their opinion on your work in progress. If your grammar makes the story hard to read, it's not nitpicky for said readers point that out to you, even if it has nothing to do with story itself.

    You're being unnecessarily abrasive, especially to whiteflags who tried to cut you some slack (if you haven't noticed).

  10. #25
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by whiteflags View Post
    Your welcome. I just wanted to explain what to do in general because the seeking around the file isn't really helping you do it right.


    I'm giving you my opinion. You are welcome to ignore it if you like.

    Why is your attitude so bad toward criticism in general? It really seems like whenever the thread shifts in a direction you didn't plan on, any other comments we make other than what you strictly want to talk about, you treat it like a personal attack.


    The only problem being discussed is the one mentioned in post 15, because that is what you were talking about at the time. I thought it would be clear in context, because I depended on you to remember what you were talking about.
    there is a big difference between constructive criticism and just plain criticism for the sake of criticizing what someone else has done.

  11. #26
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by Guest View Post
    But there needs to be a system to it, and some styles are clearly more readable than others. And programming is an area where order is of particular importance. The analogous situation here would be that you're a writer and want others to give their opinion on your work in progress. If your grammar makes the story hard to read, it's not nitpicky for said readers point that out to you, even if it has nothing to do with story itself.

    You're being unnecessarily abrasive, especially to whiteflags who tried to cut you some slack (if you haven't noticed).
    I agree that their needs to be a "format to it for readability" even I find myelf getting anal over how I indent and close off my codes but to try and say what I have posted in here is not readable it is a mess ? Let me go mess it up and make it really hard to make sense of

    for her to say it is not "formatted perfectly" so she is going to cut me a break .
    . not perfect to whos standards? their is no standard.


    so yes who made her Lord and Master over how I indent and use me brackets I can say the same about her formatting of code if I wanted to.

    Formatting is just someone idea and maybe a few others agreeing, " yeah I like it if it was written like this", then someone comes along and says no, I like it this way better. it is just an option the compiler could care less. If it really mattered in a long run then it'd not compile until it was formatted a certain way, there are only a few old languages that have this requirement. C and C++ and Pascal and Java to name s few are NOT one of them.

    the code itself is more important then the way it is formatted. what good is it to have it all pretty looking just the way YOU want it if it does not even work? that is a waste of time, spend more time trying to get it to look pretty then get it to work. great time management going on there.

    etc...
    Last edited by userxbw; 11-15-2017 at 04:49 PM.

  12. #27
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    I couldn't read it because it wasn't formatted correctly. I "scan" code, not read every single statement, for my first pass over newly presented code and your (lack of) formatting made that impossible (not to mention the lack of functions and structure in general).

  13. #28
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Formatting is just someone idea and maybe a few others agreeing,
    Yes, formatting style is a personal choice, unless you work for someone else in which case you should follow the style of your employer.

    However few people will argue that using an inconsistent style is a good practice. Consistency is one of the biggest factors that make reading "foreign" code easier to read.

    the code itself is more important then the way it is formatted.
    I would tend to disagree with this statement. IMO, if the code is hard to read because of poor formatting it will be much harder to tell if the code is really working correctly. So I would say that proper formatting should be as important as the code itself. And with today's auto formatting editors it should be easier to maintain proper formatting than writing code that functions as expected.

    By the way, while I think your code needs work on the consistency front, I don't consider the code you posted in this topic that horrible. Could it be improved, yes. Is it worth throwing tantrums from either side, doubtful.

  14. #29
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by jimblumberg View Post
    Yes, formatting style is a personal choice, unless you work for someone else in which case you should follow the style of your employer.

    However few people will argue that using an inconsistent style is a good practice. Consistency is one of the biggest factors that make reading "foreign" code easier to read.


    I would tend to disagree with this statement. IMO, if the code is hard to read because of poor formatting it will be much harder to tell if the code is really working correctly. So I would say that proper formatting should be as important as the code itself. And with today's auto formatting editors it should be easier to maintain proper formatting than writing code that functions as expected.

    By the way, while I think your code needs work on the consistency front, I don't consider the code you posted in this topic that horrible. Could it be improved, yes. Is it worth throwing tantrums from either side, doubtful.
    the order of importance
    get the code to work
    then make it look purrrrrty

    trying to keep it is somewhat an ordered fashion while trying to get it to work would be advisable as apposed to tabbed and spaced and lined in a haphazard fashion even the one coding it is having a hard time figuring out what he or she is doing. Bracket happy people bug me but I am no in here telling them it is not the way to do it. If I copy paste and play with the code I may change it to make it easier for me to read though

    Consistency is one of the biggest factors that make reading "foreign" code easier to read.

    too can be cause for argument. one mans consistency is not another mans consistency. to make "foreign" code easier to read.

    Code:
    if ( true)
    {
    do this
    }
    else if ( true )
    {
    do this
    }
    else
    {
    do this
    }
    // when it is legal to do this
    if ( true)
        do this
    else if ( true)
       do this
    else
      do this
    
    // this is legal, no brackets
    for ( int i = 0; i < 10; i++)
         if ( true)
              do this
    // what rules control that code flow? 
    // where most will say it has to be like this.
    for ( int i = 0; i < 10; i++)
    {
         if ( true)
          {
              do this
          }
    }
    // when it does not have to be
    // but there are them that will
    //complain and criticize it 
    // trying to get the coder 
    // to conform to
    // there ridged mind set.
    even
    Code:
    if ( true ) do this;
    // is the same as
    if ( true ) 
        do this
    // is the same as 
    if (true)
    {
        do this
    }
    //is the same as 
    if (true) { do this }
    
    //even 
    if (true) { do this; and this; and this;  }
    so who is right and who is wrong?
    no one is right or wrong.
    Last edited by userxbw; 11-15-2017 at 06:02 PM.

  15. #30
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    I give up. You obviously have no intention of learning or even trying to become a better programmer.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Append a temp file to a log file
    By Randellk02 in forum C Programming
    Replies: 9
    Last Post: 11-07-2010, 01:46 PM
  2. How to write image data to binary PGM file format(P5)?
    By tommy_chai in forum C Programming
    Replies: 6
    Last Post: 11-03-2007, 10:52 PM
  3. handling file rb+ (write back into self)
    By IsmAvatar2 in forum C Programming
    Replies: 5
    Last Post: 01-23-2007, 09:47 PM
  4. Deleting a temp file
    By Oldman47 in forum C++ Programming
    Replies: 1
    Last Post: 01-02-2007, 07:04 PM
  5. How to read/write 8xp file format...
    By supertoad in forum Tech Board
    Replies: 2
    Last Post: 04-29-2005, 04:18 AM

Tags for this Thread