strcmp

Warning: comparison with string literals results in unspecified behaviour

匿名 (未验证) 提交于 2019-12-03 01:52:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am starting a project of writing a simplified shell for linux in C. I am not at all proficient with C nor with Linux that's exactly the reason I decided it would be a good idea. Starting with the parser, I have already encountered some problems. The code should be straightforward that's why I didn't include any comments. I am getting a warning with gcc: "comparison with string literals results in unspecified behaviour" at the lines commented with "WARNING HERE" (see code below). I have no idea why this causes an warning, but the

strcmp equivelant for integers (intcmp) in PHP

匿名 (未验证) 提交于 2019-12-03 01:52:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: So we got this function in PHP strcmp(string $1,string $2) // returns -1,0, or 1; We Do not however, have an intcmp(); So i created one: function intcmp($a,$b) { if((int)$a == (int)$b)return 0; if((int)$a > (int)$b)return 1; if((int)$a This just feels dirty. What do you all think? this is part of a class to sort Javascripts by an ordering value passed in. class JS { // array('order'=>0,'path'=>'/js/somefile.js','attr'=>array()); public $javascripts = array(); ... public function __toString() { uasort($this->javascripts,array($this,

Comparing two ISO8601 dates strings in PHP

匿名 (未验证) 提交于 2019-12-03 01:47:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I need to compare (actually rank/sort) dates in a PHP script. The dates are ISO-8601 Date format i.e. YYYY-MM-DD I wrote a comparison function which splits the dates and compares by year/month/day. However, it seems this may be overkill and I could just as easily done a simple string comparison like: if ($date1 $date2) //do something else else //do yet another thing Is my assumption about (ISO-8601) Date string comparison correct - i.e. can I get rid of my function (to save a few clock cycles on the server), or is it safer to explicity do

How to run “host” functions on GPU with CUDA?

匿名 (未验证) 提交于 2019-12-03 01:47:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm going to run on GPU for example a strcmp function, but I get: error : calling a host function ( "strcmp" ) from a __device__ / __global__ function ( "myKernel" ) is not allowed It's possible that printf won't work because gpu hasn't got stdout, but functions like strcmp are expected to work! So, I should insert in my code the implement of strcmp from the library with __device__ prefix or what? 回答1: CUDA has a standard library, documented in the CUDA programming guide. It includes printf() for devices that support it (Compute

How can BlueZ be configured to require a connecting device to enter a matching pass key?

匿名 (未验证) 提交于 2019-12-03 01:39:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to setup Bluetooth on an embedded Linux device such that SSP mode is used, with my device generating and displaying a passcode on it's display, and the remote end (e.g. user's phone) being required to enter the matching passcode to be able to successfully pair. I'm written/registered an agent that sets it's mode to DisplayOnly; I expected that when a device connects the "RequestPasskey" callback would be called and that my agent would then be able to generate and return a new passcode, and that the remote end would be required to

Compare equality of char[] in C

匿名 (未验证) 提交于 2019-12-03 01:15:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have two variables: char charTime [] = "TIME" ; char buf [] = "SOMETHINGELSE" ; I want to check if these two are equal... using charTime == buf doesn't work. What should I use, and can someone explain why using == doesn't work? Would this action be different in C and C++? 回答1: char charTime [] = "TIME" ; char buf [] = "SOMETHINGELSE" ; C++ and C (remove std:: for C): bool equal = ( std :: strcmp ( charTime , buf ) == 0 ); But the true C++ way: std :: string charTime = "TIME" , buf = "SOMETHINGELSE" ; bool equal = ( charTime ==

Testing string equality issue

匿名 (未验证) 提交于 2019-12-03 01:09:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Haven't programmed in C in a while, so I'm surely missing something here but I can't figure out what it is. I have two strings, as shown below: char toMatch[] = "--exit--"; char entry[1024]; Through this program, I have a while loop that accepts user input to modify the string entry throughout the program. I would like to exit this while loop when entry equals toMatch . I thought this was easy to do with the strcmp function, but it's not working for some reason. Originally I had this: while(strcmp(entry, toMatch) != 0) { // accept user input

决策树―西瓜书课后题4.3―MATLAB代码

匿名 (未验证) 提交于 2019-12-03 00:34:01
题目:编程实现基于信息熵进行划分选择的决策树算法,并为西瓜数据集3.0上(P84表4.3)中的数据生成一棵决策树; 代码: clc; clear all; [num,txt]=xlsread('D:\机器学习\WaterMelon_3.0.xlsx'); data=txt(2:end,[2:7,10]); [rows,cols] = size(data); for i=1:rows for j=1:cols %离散值:Discrete_value D_value(i,j)=string2num(data(i,j)); end end %连续值:Continue_value C_value=[num(:,[8,9]),D_value(:,7)]; make_tree(D_value,C_value); %% %建树 function make_tree(data,data1) [m,n] = size(data); [m1,n1] = size(data1); disp('/////////////////////////////////////////////'); disp('待分数据集'); disp(data); disp(data1); label = data(:,n); same_class_num = length(find(data(:,n) == label(1

the if case in this code doesnt work while there is no syntax error

谁说胖子不能爱 提交于 2019-12-02 22:59:14
问题 if(s.name=="kolkata") { printf("the details"); } if(strcmp((s.name,"kolkata")==0) { printf("the details"); } The first 'if' case has no syntax error still it doesn't work,while the second 'if' case does work very efficiently, why? 回答1: It is not like the first case doesn't work at all, it just works in a way which is not intended . As per the code, if(s.name=="kolkata") is an attempt to compare the pointers themselves. It does not compare the content of the memory location pointer by these

CTF中常见的PHP漏洞

匿名 (未验证) 提交于 2019-12-02 22:11:45
1.MD5()漏洞 php在处理字符串时会利用!=,||,==进行hash值的比较 他把每一个“0E’开头的哈希值都解释为0,因此如果两个不同的密码经过hash处理之后都是以‘0e’开头,那么PHP会认为两者是相同的,南京邮电大学一次ctf上就出了一道这个题。一些经md5()后以0e开头的例子 s878926199a 0e545993274517709034328855841020 s155964671a 0e342768416822451524974117254469 s214587387a 0e848240448830537924465865611904 s214587387a 0e848240448830537924465865611904 验证一下这个现象。 <?php if(md5("s155964671a")==md5("s214587387a")) { echo "successful"; } ?> 说到md5就还有一个经典案例就是 数组的MD5值都相等 都为NULL, 这里写了一小段代码 <?php if(isset($_GET['hsy']) and isset($_GET['zyg'])){ if($_GET['hsy']!=$_GET['zyg']) { if(md5($_GET['hsy'])==md5($_GET['zyg'])) echo "yes";