public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "beyzman at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/67669] New: Wrong works fwrite or fread or both Date: Mon, 21 Sep 2015 13:25:00 -0000 [thread overview] Message-ID: <bug-67669-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67669 Bug ID: 67669 Summary: Wrong works fwrite or fread or both Product: gcc Version: unknown Status: UNCONFIRMED Severity: major Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: beyzman at gmail dot com Target Milestone: --- Created attachment 36365 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36365&action=edit Example of file to be processed The program below is intended to replace every symbol with code \x00 by symbol \x20 in some file. The program was compiled by g++ for Windows from MinGW packet. In the example attached there is symbols with code \x00 after every symbols 'j'. It is intended that after program is executed, there will be symbols with code \x20 after every symbol 'j'. But it is not so. If I decomment 2 lines commented, the programm works as intended. //#include <QTCore> #include <stdio.h> #pragma hdrstop #define min(a, b) (((a) < (b)) ? (a) : (b)) int main(int argc, char *argv[]) { FILE *f; int pos; const int bufSize = 10; int length; int piece; int i; int ret; int chSw = 0; const char *fileName = argv[1]; char *buf; if (argc < 1) printf("USAGE: 02space.exe <filename>\nReplaces every symbol \\0x00 by space\n"); f = fopen(fileName,"rb+"); if (!f) { printf("Can not open file %s",argv[1]); return -1; } fseek(f,0,SEEK_END); length = ftell(f); rewind (f); ret = 0; buf = new char[bufSize]; for(piece = (int)(min(bufSize,length)); length > 0; length -= piece,piece = (int)(min(bufSize,length))) { ++ret; pos = ftell(f) ; fread(buf,piece,1,f); chSw = 0; for (i = 0; i < piece; ++i) { if (buf[i] == '\x00') { buf[i] = ' '; chSw = 1; } } if (chSw) { fseek(f,pos,SEEK_SET); fwrite(buf,piece,1,f); // fseek(f,pos,SEEK_SET); // fread(buf, piece, 1,f); } } delete [] buf; fclose(f); return 0; }
next reply other threads:[~2015-09-21 13:25 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2015-09-21 13:25 beyzman at gmail dot com [this message] 2015-09-21 13:28 ` [Bug c++/67669] " beyzman at gmail dot com 2015-09-21 13:32 ` beyzman at gmail dot com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-67669-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).