考虑指向结构的指针
struct a_struct
{
int A;
};
Run Code Online (Sandbox Code Playgroud)
可以这样做:
struct a_struct *ptr;
//...
if( ptr != NULL && ptr->A == 1)
{
//work with ptr struct
}
Run Code Online (Sandbox Code Playgroud)
或者你应该在测试其字段之前测试指针是否有效.
if(ptr != NULL)
{
if(ptr->A == 1)
{
//work with ptr struct
}
}
Run Code Online (Sandbox Code Playgroud) 我如何更改下面的代码,以便Python读取两个变量中的列表然后执行操作而不会发生错误?我的代码:
bad = ['bad','terrible', 'dumb']
good = ['good','happy','awesome']
talk = raw_input("type:")
if (bad) in talk:
print "I'm sorry to hear that :("
elif (good) in talk:
print "That's good!"
Run Code Online (Sandbox Code Playgroud) 我不知道有什么问题..我已经看到了很多不同的方法,有人可以告诉我这到底是什么问题..它抛出这个错误"错误:SQLSTATE [42000]:语法错误或访问冲突:1064您的SQL语法有错误;请查看与您的MySQL服务器版本对应的手册,以便在'desc'附近使用正确的语法VALUES('30 .59','blue shirt','一件非常酷的蓝色衬衫')'在第1行".我尝试了多种方式,结果相同..
<?php
$title = 'blue shirt';
$desc = 'a really cool blue shirt';
$price = 30.59;
$user = 'foo';
$pass = 'Bar';
try{
$conn = new PDO('mysql:host=examplehost;dbname=exampledb_name',$user,$pass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if(!$conn){
echo"couldnt connect to db";
}else {
echo 'connected like a boss!!' . '<br>';
$stmt = $conn->prepare("INSERT INTO 68_items (price, title, desc) VALUES (:price,:title,:desc)");
if(!$stmt->execute(array(
':price' => $price,
':title' => $title,
':desc' => $desc))
) {
echo'statment failed';
}else {
echo 'statment success, ' . $stmt->rowCount() . 'rows …Run Code Online (Sandbox Code Playgroud) 我在数据库中有一个表,其中包含一堆不同的控件.在我的Page_Init方法中,我需要根据传入的Session变量加载适当的控件.有没有更好的方法来执行此操作然后使用一大堆if..else语句?我有大约15到20种不同的场景,所以我不想写20个if..else语句.任何帮助是极大的赞赏!
名为"Value"的DataTable有三列:(ID,Name,Description):
ID | Name | Description
-------------------
1 | A | First
2 | B | Second
3 | C | Third
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
ControlOne c1;
ControlTwo c2;
ControlThree c3;
protected void Page_Init(object sender, EventArgs e)
{
DataSet DS = Client.GetInformation(Session["Number"].ToString());
DataRow DR = DS.Tables["Value"].Rows[0];
if (DR["Name"].ToString() == "A" && DR["Description"].ToString() == "First")
{
c1 = (ControlOne)LoadControl("~/ControlOne.ascx");
panel1.Controls.Add(c1);
}
else if (DR["Name"].ToString() == "B" && DR["Description"].ToString() == "Second")
{
c2 = (ControlTwo)LoadControl("~/ControlTwo.ascx");
panel1.Controls.Add(c2);
}
else if (DR["Name"].ToString() == "C" && …Run Code Online (Sandbox Code Playgroud) 我已在本地 Windows 7 PC 上成功安装 ImageMagick。并测试转换 C:\xampp\htdocs\test\images\a.jpg C:\xampp\htdocs\test\images\b.jpg
但是当我从一个名为 C:\xampp\htdocs\test\index.php 的 PHP 文件中尝试使用代码时
<?php
exec("C:\Program Files\ImageMagick-6.8.9-Q16\convert C:\xampp\htdocs\test\images\a.jpg C:\xampp\htdocs\test\images\b.jpg", $output, $return);
?>
Run Code Online (Sandbox Code Playgroud)
这是行不通的。a.jpg 文件存在。我正在使用浏览器运行带有路径的 index.php 文件http://localhost/test/index.php
$output 为空,$return 为 1。
但是当我使用
<?php
exec("C:\Program Files\ImageMagick-6.8.9-Q16\convert", $output, $return);
?>
Run Code Online (Sandbox Code Playgroud)
我得到的输出是 Imagemagick 版本......如果我在命令提示符下运行命令“convert”,输出相同。我在 Windows 7 中使用 xamp。我已经搜索了很多,但是那里提到的问题并不是我所面临的。
因为当我在 PHP exec 中只使用“转换”时,我得到了输出。
所以无法理解实际问题是什么。
我在Grails中有一个列表和JSONArray,如下所示:
def siteList = []
def siteURLArray = new JSONArray()
siteURLArray.put(foo)
Run Code Online (Sandbox Code Playgroud)
如何将JSONArray转换成列表?下面不起作用
siteList = siteURLArray as List
Run Code Online (Sandbox Code Playgroud) 任何人都可以帮助我理解这相当于400?我无法弄清楚它是如何for工作的.
import java.util.*; //for class Scanner
public class Exercise
{
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
int value =0;
for (int num = 10; num<= 40; num +=2){
value =value+num;
}
System.out.println(value);
}
Run Code Online (Sandbox Code Playgroud) 经过长时间的搜索,我没有找到我要找的东西,或者如果我这样做,它对我正在做的事情不起作用,或者我不知道如何正确使用它.在所有情况下,我真的需要你的帮助.
我所做的是processing通过仅识别带有ID的div 来定义我的div,然后用jQuery编写其余的div.有很多代码,所以我会提出一个缩短版本.
<div id="blue" class='processing'>
<div class="bar"></div>
<div class="text">BLUE</div>
</div>
<div id="red" class='processing'>
<div class="bar"></div>
<div class="text">RED</div>
</div>
<div id="yellow" class='processing'>
<div class="bar"></div>
<div class="text">YELLOW</div>
</div>
Run Code Online (Sandbox Code Playgroud)
$(".processing").click(function () {
var $this = $(this);
var ID = $this.attr('id');
switch(ID){
case "blue":
var name = $this.find(".text").text();
var width = 60;
// some other var(s)
break;
case "red":
var name = $this.find(".text").text();
var width = 40;
// some other var(s)
break;
case "yellow":
var name = $this.find(".text").text();
var …Run Code Online (Sandbox Code Playgroud) 我确定这是一个新手问题,但我不明白.each()普通$()选择器有什么好处.该$()选择什么样的选择是,适用什么都被应用到了选择它的所有匹配的情况下,所有实例.我的直接反应是:很好地.each()允许更复杂的事情,但你可以使用jquery方法链,所以我也可以使用普通选择器做更复杂的事情.例如,如果我有5个p元素,我写:
$("p").css("color","blue");//this would be applied to all five p elements
$("p").each(function(){$(this).css("color","blue")});//this does the
//same thing
Run Code Online (Sandbox Code Playgroud)
我确定有一个用途.each(),我目前只是看不到它,正常的选择器似乎已经遍历了所有内容.有人可以举例说明我为什么要使用它.each()吗?
我需要使用 Jackson 解析字符串(标识符)数组。我在互联网上没有找到任何示例,它们都展示了如何反序列化某个类的对象数组,但我只需要解析字符串数组(无需为其编写模型类),我该如何去做?JSON 示例:
[
"UUID",
"UUID",
...
]
Run Code Online (Sandbox Code Playgroud)