Pelles C forum
News
: Version 6.00 released!
Home
Help
Search
Login
Register
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
September 06, 2010, 08:48:23 PM
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Pelles C forum
>
Pelles C
>
Bug reports
>
Access violation while call strtok function (write to read-only rdata section)
Pages: [
1
]
Go Down
« previous
next »
Print
Author
Topic: Access violation while call strtok function (write to read-only rdata section) (Read 280 times)
BottleNeck
Member
Offline
Posts: 2
Access violation while call strtok function (write to read-only rdata section)
«
on:
June 29, 2010, 09:03:14 PM »
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;
}
Logged
iZzz32
Member
Offline
Posts: 22
Re: Access violation while call strtok function (write to read-only rdata sectio
«
Reply #1 on:
June 30, 2010, 06:05:56 AM »
Not a bug. String literals are constants. Use:
Code:
char str[] = "LINE TO BE SEPARATED";
Logged
BottleNeck
Member
Offline
Posts: 2
Re: Access violation while call strtok function (write to read-only rdata section)
«
Reply #2 on:
June 30, 2010, 10:09:24 AM »
Example above I get from
http://www.opengroup.org/onlinepubs/000095399/functions/strtok.html
Thank you for explanation.
Logged
Pages: [
1
]
Go Up
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
Pelles C forum
-----------------------------
=> Announcements
-----------------------------
C language
-----------------------------
=> Beginner questions
=> Expert questions
=> Windows questions
=> Pocket PC and Smartphone questions
=> Work in progress
=> User contributions
=> Tips & tricks
=> Graphics programming
-----------------------------
Assembly language
-----------------------------
=> Assembly discussions
-----------------------------
Pelles C
-----------------------------
=> General discussions
=> Bug reports
=> Feature requests
=> Add-ins
=> FAQ
=> Announcements
-----------------------------
General
-----------------------------
=> Chit-Chat
-----------------------------
Test
-----------------------------
=> Test
Loading...