[GO] C> strtok ()> runtime error> string literal cannot be used

http://qiita.com/7of9/items/e28895f22afda103092e#comment-98a5487d3db42a0ecd16 I was addicted to trying to create my own function based on the comments I made.

To put it in order, string literal cannot be used as a string to be passed to strtok ().

Reference http://stackoverflow.com/questions/32844304/splitting-char-array-using-strtok-giving-runtime-error

You can't call strtok() on a string literal, because string literals are constant.

I get a runtime error with the following code.

http://ideone.com/jcTotE

#include <stdio.h>
#include <string.h>

static const char *s_rcvd = "pval,3.141,2.718,6.022"; // dummy data

int main(void) {
	char *tp;
	
	tp = strtok(s_rcvd, ",");

	return 0;
}

After copying the above s_rcvd to szbuf declared as char szbuf [120]; with strcpy (szbuf, s_rcvd) ;, strtok (szbuf, ","); no longer causes a runtime error.

Use string literals when testing functions. In normal processing, it is a character string declared as char [] instead of string literal.

Recommended Posts

C> strtok ()> runtime error> string literal cannot be used
No module named'distutils.util' cannot be used with get-pip.py
The problem that the ifconfig command cannot be used