Replace an image in C using binary mode

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Savage
    Recognized Expert Top Contributor
    • Feb 2007
    • 1759

    #31
    Originally posted by DeMan
    you could use sizeof(char)... .
    Allready tryed that.

    Same thing happens.

    Savage

    Comment

    • ematlis
      New Member
      • Jun 2007
      • 1

      #32
      Before reading the file, you need to rewind it. The fseek command put you at the end of it, so no data is being read into your buffer. Use:

      rewind(file_poi nter)

      where file_pointer refers to the file pointer of your input file, I believe it was "newpic".

      thanks,
      eric

      Comment

      • Savage
        Recognized Expert Top Contributor
        • Feb 2007
        • 1759

        #33
        Originally posted by ematlis
        Before reading the file, you need to rewind it. The fseek command put you at the end of it, so no data is being read into your buffer. Use:

        rewind(file_poi nter)

        where file_pointer refers to the file pointer of your input file, I believe it was "newpic".

        thanks,
        eric
        LOL,we all missed that.

        Sharp eye eric..

        Savage

        Comment

        • niskin
          New Member
          • Apr 2007
          • 109

          #34
          hate to say it but it's still not working :S

          Comment

          • Savage
            Recognized Expert Top Contributor
            • Feb 2007
            • 1759

            #35
            Originally posted by niskin
            hate to say it but it's still not working :S
            Can you shouw us your code?

            And please can you tell us how it's not working?

            Does it sitll copie a few characters or is it something else?

            Savage

            Comment

            • DeMan
              Top Contributor
              • Nov 2006
              • 1799

              #36
              fread (and I think fwrote also), return a value, this value represents the size read (or written).....
              YOu might like to retrieve these values and print them to see whether one of these functions is causing the unexpected behaviour

              Comment

              • Savage
                Recognized Expert Top Contributor
                • Feb 2007
                • 1759

                #37
                Originally posted by DeMan
                fread (and I think fwrote also), return a value, this value represents the size read (or written).....
                YOu might like to retrieve these values and print them to see whether one of these functions is causing the unexpected behaviour
                Sorry Deman, but you are wrong, fread and fwrite returns number of elements readed/writen..

                Still, OP can multiply with sizeof one element and that way discover unexpected behaviour, if there is one..

                Savage

                Comment

                • DeMan
                  Top Contributor
                  • Nov 2006
                  • 1799

                  #38
                  Originally posted by Savage
                  fread and fwrite returns number of elements readed/writen..
                  Are you suggesting that number of elements does not constitute size (You'll notice units were never mentioned)?

                  Comment

                  • Savage
                    Recognized Expert Top Contributor
                    • Feb 2007
                    • 1759

                    #39
                    Originally posted by DeMan
                    Are you suggesting that number of elements does not constitute size (You'll notice units were never mentioned)?
                    It depandes on what is the size of the element user requested when he called fread or fwrite.If it is 1byte then you are correct,but if it is more bytes per element he will need to multiply returned value with size of single element readed/writen

                    Savage

                    Comment

                    • DeMan
                      Top Contributor
                      • Nov 2006
                      • 1799

                      #40
                      Granted, to get the size in bytes, number of elements needs to be mulktiplied by number of bytes in an element. But number of elements is still size (3 metres is still 3 metres even if it is 300 centimetres as well).

                      While printing the size in bytes may also be useful, I think it may also be helpful to print the size in number of elements, after all, you should probably consider data in its' rawest form if you want to find such peculiarities.

                      I appreciate that the size returned by these functions is not the size in bytes, however, I never suggested that it was, and feel my suggestion was worthwhile nonetheless.... .

                      Comment

                      • Savage
                        Recognized Expert Top Contributor
                        • Feb 2007
                        • 1759

                        #41
                        Originally posted by DeMan
                        Granted, to get the size in bytes, number of elements needs to be mulktiplied by number of bytes in an element. But number of elements is still size (3 metres is still 3 metres even if it is 300 centimetres as well).

                        While printing the size in bytes may also be useful, I think it may also be helpful to print the size in number of elements, after all, you should probably consider data in its' rawest form if you want to find such peculiarities.

                        I appreciate that the size returned by these functions is not the size in bytes, however, I never suggested that it was, and feel my suggestion was worthwhile nonetheless.... .
                        Sorry.

                        I thought that you are trying to tell that those functions returns size in bytes.

                        Savage

                        Comment

                        Working...