什么S [-1] = 0是什么意思? [英] What does s[-1] = 0 mean?
本文介绍了什么S [-1] = 0是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我学习函数strtok的code来自BSD的libc中,当我在我的机器上运行它,
该程序接收到的信号 SIGSEGV
在 S [-1] = 0
。
这里的链接到code。
是 S [-1] = 0
吧?
这是我的code:
的#include<&stdio.h中GT;
#包括LT&;&stdlib.h中GT;
#包括strtok.cINT主(INT ARGC,CHAR *的argv []){
字符*海峡=XXXX xxxyy fdffd
为const char * s =; 字符*令牌= strtok的(STR,S); 而(令牌!= NULL){
的printf(%S \\ N标记);
令牌= strtok的(NULL,S);
} 返回0;
}
解决方案
S [-1]
被扩展为:
*(S - 1)
因此,如果结果指向有效的存储器,所述code定义
I'm studying the code of the function strtok from bsd's libc, when I ran it in my machine,
the program received signal SIGSEGV
in s[-1] = 0
.
Here's the link to the code.
Is s[-1] = 0
right?
This is my code:
#include <stdio.h>
#include <stdlib.h>
#include "strtok.c"
int main(int argc, char* argv[]) {
char* str = "xxxx xxxyy fdffd";
const char* s = " ";
char* token = strtok(str, s);
while (token != NULL) {
printf("%s\n", token);
token = strtok(NULL, s);
}
return 0;
}
解决方案
s[-1]
Is expanded to:
*( s - 1 )
Therefore, if the result points to valid memory, the code is defined.
这篇关于什么S [-1] = 0是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文