NO

Author Topic: Access violation while call strtok function (write to read-only rdata section)  (Read 5005 times)

BottleNeck

  • Guest
Problem is in trying to write to .rdata section of produced .exe file, because of 40000040 (only readable) section flags.
Set it to C0000040 (readable and writeable) solve the problem (but only with hex editor).
Code sample:
#include <stdio.h>
#include <string.h>

int main(void)
{
  char *p;
   char *str = "LINE TO BE SEPARATED";
   char *delimiter =  " ";
  p = strtok(str,delimiter);
  printf(p);
  do {
    p = strtok('\0', ", ");
    if(p) printf("|%s", p);
  } while(p);

  return 0;
}


iZzz32

  • Guest
Not a bug. String literals are constants. Use:
Code: [Select]
char str[] = "LINE TO BE SEPARATED";

BottleNeck

  • Guest
Example above I get from http://www.opengroup.org/onlinepubs/000095399/functions/strtok.html
Thank you for explanation.