sscanf reads one character instead of the entire string (mmap)












1















I was using memory mapping to "edit" one file and print the results to another, when I encountered this phenomenon. My understanding is that sscanf (similar to printf) reads a string until a whitespace or newline is encountered. This was exactly my tactic, when I used it on my mmap'd source file to filter out the comments and print everything else to second file. For a given argument of how the comment line starts (a string e.g. "#", "@","//", "whatever"), I used sscanf to check if a line began with that word. Much to my surprise it seems that when mmap is used, the pointer to that virtual memory isn't treated the same. (note the test printf right before the while loop).



#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <sys/mman.h>
#include <unistd.h>

static void fatalError(char *message);

int main(int argc, char *argv)
{
int fd1, fd2;
struct stat stats;
char *source, *dest;


assert(argc == 4);

if ((fd1 = open(argv[1], O_RDONLY)) < 0) {
if (errno == ENOENT)
fatalError("First file nonexistent");
else
fatalError("open error");
}


if ((fd2 = open(argv[2], O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH)) < 0) {
if (errno == EACCES)
printf("Creating second filen");
else
fatalError("open error");
}


if (fstat(fd1, &stats) < 0)
fatalError("fstat error");

if (lseek(fd2, stats.st_size-1, SEEK_SET) < 0)
fatalError("lseek error");

if (write(fd2, "", 1) != 1)
fatalError("write error");


if ((source = mmap(0, stats.st_size, PROT_READ, MAP_SHARED, fd1, 0)) == MAP_FAILED)
fatalError("mmap failed");

if ((dest = mmap(0, stats.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd2, 0)) == MAP_FAILED)
fatalError("mmap failed");

char word[100];
int flag, count;
char *tmp;

tmp = source;

char test[50] = "firstWord will only be read by sscanf";
sscanf(test, "%s", word);
printf("%sn", word);

while ((count = sscanf(source, "%s", word)) > 0) {
if (!flag) {
// in comment
if (!strcmp(word, argv[3])) {
flag = 1;
source += count;
continue;
}
sprintf(dest, "%s", word);
source += count;
} else {
// not in comment
if (word[strlen(word) - 1] == 'n') {
sprintf(dest, "n");
source += count;
}

source += count;

}

}

source = tmp;

if (munmap(source, stats.st_size) < 0)
fatalError("munmap error");

if (munmap(dest, stats.st_size) < 0)
fatalError("munmap error");

if (close(fd1) < 0)
fatalError("close return");

if (close(fd2) < 0)
fatalError("close error");




return 0;
}


static void fatalError(char *message) {
perror(message);
exit(EXIT_FAILURE);
}


The input file("#" as comment symbol):



npwhitespacea
asdasdasdasd
# asdasdasdasmdaosimda
asdasd
kmflsdkfms
#
oioiasjdoaisd
i
# asoidaosid









share|improve this question


















  • 1





    How are you creating your input file? Are you sure it's not encoded and written as wide characters? Can you do a hex or octal dump of the file contents?

    – Andrew Henle
    Jan 20 at 0:51








  • 1





    Please read the docs when you use a function. sscanf returns the number of items read (1), not the number of characters.

    – stark
    Jan 20 at 1:01











  • You also don't initialize flag before you test it the first time...

    – Chris Dodd
    Jan 20 at 4:25
















1















I was using memory mapping to "edit" one file and print the results to another, when I encountered this phenomenon. My understanding is that sscanf (similar to printf) reads a string until a whitespace or newline is encountered. This was exactly my tactic, when I used it on my mmap'd source file to filter out the comments and print everything else to second file. For a given argument of how the comment line starts (a string e.g. "#", "@","//", "whatever"), I used sscanf to check if a line began with that word. Much to my surprise it seems that when mmap is used, the pointer to that virtual memory isn't treated the same. (note the test printf right before the while loop).



#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <sys/mman.h>
#include <unistd.h>

static void fatalError(char *message);

int main(int argc, char *argv)
{
int fd1, fd2;
struct stat stats;
char *source, *dest;


assert(argc == 4);

if ((fd1 = open(argv[1], O_RDONLY)) < 0) {
if (errno == ENOENT)
fatalError("First file nonexistent");
else
fatalError("open error");
}


if ((fd2 = open(argv[2], O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH)) < 0) {
if (errno == EACCES)
printf("Creating second filen");
else
fatalError("open error");
}


if (fstat(fd1, &stats) < 0)
fatalError("fstat error");

if (lseek(fd2, stats.st_size-1, SEEK_SET) < 0)
fatalError("lseek error");

if (write(fd2, "", 1) != 1)
fatalError("write error");


if ((source = mmap(0, stats.st_size, PROT_READ, MAP_SHARED, fd1, 0)) == MAP_FAILED)
fatalError("mmap failed");

if ((dest = mmap(0, stats.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd2, 0)) == MAP_FAILED)
fatalError("mmap failed");

char word[100];
int flag, count;
char *tmp;

tmp = source;

char test[50] = "firstWord will only be read by sscanf";
sscanf(test, "%s", word);
printf("%sn", word);

while ((count = sscanf(source, "%s", word)) > 0) {
if (!flag) {
// in comment
if (!strcmp(word, argv[3])) {
flag = 1;
source += count;
continue;
}
sprintf(dest, "%s", word);
source += count;
} else {
// not in comment
if (word[strlen(word) - 1] == 'n') {
sprintf(dest, "n");
source += count;
}

source += count;

}

}

source = tmp;

if (munmap(source, stats.st_size) < 0)
fatalError("munmap error");

if (munmap(dest, stats.st_size) < 0)
fatalError("munmap error");

if (close(fd1) < 0)
fatalError("close return");

if (close(fd2) < 0)
fatalError("close error");




return 0;
}


static void fatalError(char *message) {
perror(message);
exit(EXIT_FAILURE);
}


The input file("#" as comment symbol):



npwhitespacea
asdasdasdasd
# asdasdasdasmdaosimda
asdasd
kmflsdkfms
#
oioiasjdoaisd
i
# asoidaosid









share|improve this question


















  • 1





    How are you creating your input file? Are you sure it's not encoded and written as wide characters? Can you do a hex or octal dump of the file contents?

    – Andrew Henle
    Jan 20 at 0:51








  • 1





    Please read the docs when you use a function. sscanf returns the number of items read (1), not the number of characters.

    – stark
    Jan 20 at 1:01











  • You also don't initialize flag before you test it the first time...

    – Chris Dodd
    Jan 20 at 4:25














1












1








1








I was using memory mapping to "edit" one file and print the results to another, when I encountered this phenomenon. My understanding is that sscanf (similar to printf) reads a string until a whitespace or newline is encountered. This was exactly my tactic, when I used it on my mmap'd source file to filter out the comments and print everything else to second file. For a given argument of how the comment line starts (a string e.g. "#", "@","//", "whatever"), I used sscanf to check if a line began with that word. Much to my surprise it seems that when mmap is used, the pointer to that virtual memory isn't treated the same. (note the test printf right before the while loop).



#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <sys/mman.h>
#include <unistd.h>

static void fatalError(char *message);

int main(int argc, char *argv)
{
int fd1, fd2;
struct stat stats;
char *source, *dest;


assert(argc == 4);

if ((fd1 = open(argv[1], O_RDONLY)) < 0) {
if (errno == ENOENT)
fatalError("First file nonexistent");
else
fatalError("open error");
}


if ((fd2 = open(argv[2], O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH)) < 0) {
if (errno == EACCES)
printf("Creating second filen");
else
fatalError("open error");
}


if (fstat(fd1, &stats) < 0)
fatalError("fstat error");

if (lseek(fd2, stats.st_size-1, SEEK_SET) < 0)
fatalError("lseek error");

if (write(fd2, "", 1) != 1)
fatalError("write error");


if ((source = mmap(0, stats.st_size, PROT_READ, MAP_SHARED, fd1, 0)) == MAP_FAILED)
fatalError("mmap failed");

if ((dest = mmap(0, stats.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd2, 0)) == MAP_FAILED)
fatalError("mmap failed");

char word[100];
int flag, count;
char *tmp;

tmp = source;

char test[50] = "firstWord will only be read by sscanf";
sscanf(test, "%s", word);
printf("%sn", word);

while ((count = sscanf(source, "%s", word)) > 0) {
if (!flag) {
// in comment
if (!strcmp(word, argv[3])) {
flag = 1;
source += count;
continue;
}
sprintf(dest, "%s", word);
source += count;
} else {
// not in comment
if (word[strlen(word) - 1] == 'n') {
sprintf(dest, "n");
source += count;
}

source += count;

}

}

source = tmp;

if (munmap(source, stats.st_size) < 0)
fatalError("munmap error");

if (munmap(dest, stats.st_size) < 0)
fatalError("munmap error");

if (close(fd1) < 0)
fatalError("close return");

if (close(fd2) < 0)
fatalError("close error");




return 0;
}


static void fatalError(char *message) {
perror(message);
exit(EXIT_FAILURE);
}


The input file("#" as comment symbol):



npwhitespacea
asdasdasdasd
# asdasdasdasmdaosimda
asdasd
kmflsdkfms
#
oioiasjdoaisd
i
# asoidaosid









share|improve this question














I was using memory mapping to "edit" one file and print the results to another, when I encountered this phenomenon. My understanding is that sscanf (similar to printf) reads a string until a whitespace or newline is encountered. This was exactly my tactic, when I used it on my mmap'd source file to filter out the comments and print everything else to second file. For a given argument of how the comment line starts (a string e.g. "#", "@","//", "whatever"), I used sscanf to check if a line began with that word. Much to my surprise it seems that when mmap is used, the pointer to that virtual memory isn't treated the same. (note the test printf right before the while loop).



#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <sys/mman.h>
#include <unistd.h>

static void fatalError(char *message);

int main(int argc, char *argv)
{
int fd1, fd2;
struct stat stats;
char *source, *dest;


assert(argc == 4);

if ((fd1 = open(argv[1], O_RDONLY)) < 0) {
if (errno == ENOENT)
fatalError("First file nonexistent");
else
fatalError("open error");
}


if ((fd2 = open(argv[2], O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH)) < 0) {
if (errno == EACCES)
printf("Creating second filen");
else
fatalError("open error");
}


if (fstat(fd1, &stats) < 0)
fatalError("fstat error");

if (lseek(fd2, stats.st_size-1, SEEK_SET) < 0)
fatalError("lseek error");

if (write(fd2, "", 1) != 1)
fatalError("write error");


if ((source = mmap(0, stats.st_size, PROT_READ, MAP_SHARED, fd1, 0)) == MAP_FAILED)
fatalError("mmap failed");

if ((dest = mmap(0, stats.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd2, 0)) == MAP_FAILED)
fatalError("mmap failed");

char word[100];
int flag, count;
char *tmp;

tmp = source;

char test[50] = "firstWord will only be read by sscanf";
sscanf(test, "%s", word);
printf("%sn", word);

while ((count = sscanf(source, "%s", word)) > 0) {
if (!flag) {
// in comment
if (!strcmp(word, argv[3])) {
flag = 1;
source += count;
continue;
}
sprintf(dest, "%s", word);
source += count;
} else {
// not in comment
if (word[strlen(word) - 1] == 'n') {
sprintf(dest, "n");
source += count;
}

source += count;

}

}

source = tmp;

if (munmap(source, stats.st_size) < 0)
fatalError("munmap error");

if (munmap(dest, stats.st_size) < 0)
fatalError("munmap error");

if (close(fd1) < 0)
fatalError("close return");

if (close(fd2) < 0)
fatalError("close error");




return 0;
}


static void fatalError(char *message) {
perror(message);
exit(EXIT_FAILURE);
}


The input file("#" as comment symbol):



npwhitespacea
asdasdasdasd
# asdasdasdasmdaosimda
asdasd
kmflsdkfms
#
oioiasjdoaisd
i
# asoidaosid






c mmap






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 20 at 0:20









monolith937monolith937

11819




11819








  • 1





    How are you creating your input file? Are you sure it's not encoded and written as wide characters? Can you do a hex or octal dump of the file contents?

    – Andrew Henle
    Jan 20 at 0:51








  • 1





    Please read the docs when you use a function. sscanf returns the number of items read (1), not the number of characters.

    – stark
    Jan 20 at 1:01











  • You also don't initialize flag before you test it the first time...

    – Chris Dodd
    Jan 20 at 4:25














  • 1





    How are you creating your input file? Are you sure it's not encoded and written as wide characters? Can you do a hex or octal dump of the file contents?

    – Andrew Henle
    Jan 20 at 0:51








  • 1





    Please read the docs when you use a function. sscanf returns the number of items read (1), not the number of characters.

    – stark
    Jan 20 at 1:01











  • You also don't initialize flag before you test it the first time...

    – Chris Dodd
    Jan 20 at 4:25








1




1





How are you creating your input file? Are you sure it's not encoded and written as wide characters? Can you do a hex or octal dump of the file contents?

– Andrew Henle
Jan 20 at 0:51







How are you creating your input file? Are you sure it's not encoded and written as wide characters? Can you do a hex or octal dump of the file contents?

– Andrew Henle
Jan 20 at 0:51






1




1





Please read the docs when you use a function. sscanf returns the number of items read (1), not the number of characters.

– stark
Jan 20 at 1:01





Please read the docs when you use a function. sscanf returns the number of items read (1), not the number of characters.

– stark
Jan 20 at 1:01













You also don't initialize flag before you test it the first time...

– Chris Dodd
Jan 20 at 4:25





You also don't initialize flag before you test it the first time...

– Chris Dodd
Jan 20 at 4:25












2 Answers
2






active

oldest

votes


















0














source += count; is questionable code as it is the same as source++; for count is 1 here.



Likely on a match, code should advance by the length of the string and not the conversion count.



  // in comment
if (!strcmp(word, argv[3])) {
flag = 1;
// source += count;
source += strlen(argv[3]);
continue;
}




Code is never true



word[strlen(word) - 1] == 'n' is never true because sscanf(source, "%s", word) will not put white-space into word.






sscanf (similar to printf) reads a string until a whitespace or newline is encountered.




OP's generalization is too broad. 1) the "until" depends on the format. 2) With format "%s", sscanf() reads white-spaces and skip other them, then its reads non-white-spaces and saves them. This continues until a whitespace (which include a 'n') is found. sscanf() differs from scanf/fscanf in this case as reading a null character by scanf/fscanf is read/saved just like any non-white-space. With sscanf(), a null character is akin to an end-of-file. It is not "read/saved", but does stop the scan.





OP's overall strategy have weaknesses. OP is looking for comment line. "%s" loses all awareness of 'n'.



Code could use the below to read a line, yet more work is needed for empty or very long lines.



char line[260];
int n = 0;
sscanf(source, "%259[^n]%n", line, &n);
if (line > 0) {
// success, now read potential n or more line
...
} else {
// read potential n (a short line)
...
}

// process line

// next line
source += n;




Other issues may exist.






share|improve this answer

































    0














    sscanf reads until null '' character.






    share|improve this answer

























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54272527%2fsscanf-reads-one-character-instead-of-the-entire-string-mmap%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      source += count; is questionable code as it is the same as source++; for count is 1 here.



      Likely on a match, code should advance by the length of the string and not the conversion count.



        // in comment
      if (!strcmp(word, argv[3])) {
      flag = 1;
      // source += count;
      source += strlen(argv[3]);
      continue;
      }




      Code is never true



      word[strlen(word) - 1] == 'n' is never true because sscanf(source, "%s", word) will not put white-space into word.






      sscanf (similar to printf) reads a string until a whitespace or newline is encountered.




      OP's generalization is too broad. 1) the "until" depends on the format. 2) With format "%s", sscanf() reads white-spaces and skip other them, then its reads non-white-spaces and saves them. This continues until a whitespace (which include a 'n') is found. sscanf() differs from scanf/fscanf in this case as reading a null character by scanf/fscanf is read/saved just like any non-white-space. With sscanf(), a null character is akin to an end-of-file. It is not "read/saved", but does stop the scan.





      OP's overall strategy have weaknesses. OP is looking for comment line. "%s" loses all awareness of 'n'.



      Code could use the below to read a line, yet more work is needed for empty or very long lines.



      char line[260];
      int n = 0;
      sscanf(source, "%259[^n]%n", line, &n);
      if (line > 0) {
      // success, now read potential n or more line
      ...
      } else {
      // read potential n (a short line)
      ...
      }

      // process line

      // next line
      source += n;




      Other issues may exist.






      share|improve this answer






























        0














        source += count; is questionable code as it is the same as source++; for count is 1 here.



        Likely on a match, code should advance by the length of the string and not the conversion count.



          // in comment
        if (!strcmp(word, argv[3])) {
        flag = 1;
        // source += count;
        source += strlen(argv[3]);
        continue;
        }




        Code is never true



        word[strlen(word) - 1] == 'n' is never true because sscanf(source, "%s", word) will not put white-space into word.






        sscanf (similar to printf) reads a string until a whitespace or newline is encountered.




        OP's generalization is too broad. 1) the "until" depends on the format. 2) With format "%s", sscanf() reads white-spaces and skip other them, then its reads non-white-spaces and saves them. This continues until a whitespace (which include a 'n') is found. sscanf() differs from scanf/fscanf in this case as reading a null character by scanf/fscanf is read/saved just like any non-white-space. With sscanf(), a null character is akin to an end-of-file. It is not "read/saved", but does stop the scan.





        OP's overall strategy have weaknesses. OP is looking for comment line. "%s" loses all awareness of 'n'.



        Code could use the below to read a line, yet more work is needed for empty or very long lines.



        char line[260];
        int n = 0;
        sscanf(source, "%259[^n]%n", line, &n);
        if (line > 0) {
        // success, now read potential n or more line
        ...
        } else {
        // read potential n (a short line)
        ...
        }

        // process line

        // next line
        source += n;




        Other issues may exist.






        share|improve this answer




























          0












          0








          0







          source += count; is questionable code as it is the same as source++; for count is 1 here.



          Likely on a match, code should advance by the length of the string and not the conversion count.



            // in comment
          if (!strcmp(word, argv[3])) {
          flag = 1;
          // source += count;
          source += strlen(argv[3]);
          continue;
          }




          Code is never true



          word[strlen(word) - 1] == 'n' is never true because sscanf(source, "%s", word) will not put white-space into word.






          sscanf (similar to printf) reads a string until a whitespace or newline is encountered.




          OP's generalization is too broad. 1) the "until" depends on the format. 2) With format "%s", sscanf() reads white-spaces and skip other them, then its reads non-white-spaces and saves them. This continues until a whitespace (which include a 'n') is found. sscanf() differs from scanf/fscanf in this case as reading a null character by scanf/fscanf is read/saved just like any non-white-space. With sscanf(), a null character is akin to an end-of-file. It is not "read/saved", but does stop the scan.





          OP's overall strategy have weaknesses. OP is looking for comment line. "%s" loses all awareness of 'n'.



          Code could use the below to read a line, yet more work is needed for empty or very long lines.



          char line[260];
          int n = 0;
          sscanf(source, "%259[^n]%n", line, &n);
          if (line > 0) {
          // success, now read potential n or more line
          ...
          } else {
          // read potential n (a short line)
          ...
          }

          // process line

          // next line
          source += n;




          Other issues may exist.






          share|improve this answer















          source += count; is questionable code as it is the same as source++; for count is 1 here.



          Likely on a match, code should advance by the length of the string and not the conversion count.



            // in comment
          if (!strcmp(word, argv[3])) {
          flag = 1;
          // source += count;
          source += strlen(argv[3]);
          continue;
          }




          Code is never true



          word[strlen(word) - 1] == 'n' is never true because sscanf(source, "%s", word) will not put white-space into word.






          sscanf (similar to printf) reads a string until a whitespace or newline is encountered.




          OP's generalization is too broad. 1) the "until" depends on the format. 2) With format "%s", sscanf() reads white-spaces and skip other them, then its reads non-white-spaces and saves them. This continues until a whitespace (which include a 'n') is found. sscanf() differs from scanf/fscanf in this case as reading a null character by scanf/fscanf is read/saved just like any non-white-space. With sscanf(), a null character is akin to an end-of-file. It is not "read/saved", but does stop the scan.





          OP's overall strategy have weaknesses. OP is looking for comment line. "%s" loses all awareness of 'n'.



          Code could use the below to read a line, yet more work is needed for empty or very long lines.



          char line[260];
          int n = 0;
          sscanf(source, "%259[^n]%n", line, &n);
          if (line > 0) {
          // success, now read potential n or more line
          ...
          } else {
          // read potential n (a short line)
          ...
          }

          // process line

          // next line
          source += n;




          Other issues may exist.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 20 at 5:19

























          answered Jan 20 at 4:53









          chuxchux

          82.7k872149




          82.7k872149

























              0














              sscanf reads until null '' character.






              share|improve this answer






























                0














                sscanf reads until null '' character.






                share|improve this answer




























                  0












                  0








                  0







                  sscanf reads until null '' character.






                  share|improve this answer















                  sscanf reads until null '' character.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jan 20 at 4:57









                  chux

                  82.7k872149




                  82.7k872149










                  answered Jan 20 at 0:48









                  anandanand

                  1376




                  1376






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54272527%2fsscanf-reads-one-character-instead-of-the-entire-string-mmap%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Homophylophilia

                      Updating UILabel text programmatically using a function

                      Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage