一个新手问题:
我正在练习赋予char指针,但发现没有打印出来.这是代码:
#include <stdio.h>
int main (void)
{
char * option_string = NULL;
option_string = (char*)malloc(sizeof(5));
memset(option_string, 0, sizeof(char) * 5);
int j;
for ( j = 0; j < 5; j++)
{
*option_string++ = 'a';
}
printf("print options_string: %s\n", option_string); //!nothing was printed out!
free(option_string);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
提前致谢!
params[:user][:role_ids] ||= []
Run Code Online (Sandbox Code Playgroud)
它有什么作用?
ruby -v = 1.9.2p290
我正在从Corona的示例代码中分析Fishies projest,我无法理解该任务.
background = ( backgroundLandscape == background and backgroundPortrait ) or backgroundLandscape
Run Code Online (Sandbox Code Playgroud)
这是完整的代码:
-- Seed randomizer
local seed = os.time();
math.randomseed( seed )
display.setStatusBar( display.HiddenStatusBar )
-- Preload the sound file (theoretically, we should also dispose of it when we are completely done with it)
local soundID = audio.loadSound( "bubble_strong_wav.wav" )
-- Background
local halfW = display.viewableContentWidth / 2
local halfH = display.viewableContentHeight / 2
-- Create a table to store all the fish and register this table as …Run Code Online (Sandbox Code Playgroud) 可能重复:
语法help - 作为对象名称变量
我在Objective C中有一个非常基本的初学者问题:
我想声明一个以另一个变量的content/value/literal命名的变量.我怎样才能做到这一点?
即
NSString *s = [NSString stringWithFormat:@"variableName"];
Run Code Online (Sandbox Code Playgroud)
//现在创建一个以s中的文字命名的第二个变量
int *s = 42; // This is what doesn't work. The integer-type variable should be named variableName
Run Code Online (Sandbox Code Playgroud)
有谁知道如何做到这一点?
谢谢你到目前为止的答案.我问这个问题的原因如下:
我有一个包含从xml文件加载的值的数组,结构如下:
<string>name</string><integer>23</integer><real>3.232</real><real>4.556</real> ... (44 times another real number)<string>nextName</string>...(and so on).
该文件包含MKPolygons的名称,每个多边形的点数以及多边形的每个点的纬度和逻辑值.我设法加载文件并将其内容放在一个数组中.现在我想从这个数组创建MKPolygons,它们被命名为数组中的字符串.
我试图找到答案,但似乎没有什么适合这个问题......
我想在一个简单的行中sys.argv为一个变量分配一个简单的行,而不是执行以下操作:
var1 = sys.argv[1]
var2 = sys.argv[2]
var3 = sys.argv[3]
var4 = sys.argv[4]
var5 = sys.argv[5]
var6 = sys.argv[6]
etc...
Run Code Online (Sandbox Code Playgroud)
这可能吗?
干杯,
MHibbin
我有一个自定义排序方法的数据集.我称之为:
ds.Sort( "列");
其中ds是数据集类型.然后我排序第一个表(排序代码本身不相关,因为断点显示结果是正确的).我的排序方法如下:
public static void Sort(this DataSet ds, string column)
{
DataSet newDs = ds.Copy();
//sorting occurs
ds = newDs.Copy();
} // <- breakpoint
Run Code Online (Sandbox Code Playgroud)
在断点处,ds和newDs都按照应有的顺序进行排序.但是,一旦我向前移动并在调用此排序方法后到达该行,ds将不再排序.我也尝试过这样做
ds.Clear();
Run Code Online (Sandbox Code Playgroud)
在那个Sort方法中,这次它起作用了.我不允许为对象分配值吗?是否有可能以某种方式做到这一点?
新手问题在这里.我很困惑为什么,只有在某些语法下,列表会在分配给它的其他列表得到更新时自动更新.例如,
如果我们将'a'分配给'b'并更新'b','a'仍然不受影响:
>>> b = [1,1,0]
>>> a = b
a = [1,1,0]
>>> b = [0,0,0]
a = [1,1,0]
Run Code Online (Sandbox Code Playgroud)
但是,如果我们将最后一个更新命令重写为:
>>> b[:2] = [0]*2
a = [0,0,0]
Run Code Online (Sandbox Code Playgroud)
这是为什么?
我的同事传给我一些代码,当我运行代码时会出现问题.这是它的一部分
boolean purchased = false;
conn = DriverManager.getConnection(connectionUrl, connectionUser, connectionPassword);
stmt = conn.createStatement();
String sql = new StringBuilder().... // some query
rs = stmt.executeQuery(sql);
while (rs.next()) {
//some code
purchased = rs.getInt("purchased") == 1;
print(" purchased:" + purchased);
}
Run Code Online (Sandbox Code Playgroud)
这总是打印购买为假.我改变了这个部分:
while (rs.next()) {
//some code
if(rs.getInt("purchased") == 1) purchased = true;
print(" purchased:" + purchased);
}
Run Code Online (Sandbox Code Playgroud)
现在它完美无缺.
注意: 我的ResultSet只能有1条记录.并且在购买的 DB中是位类型,因此不能有除0/1之外的其他值.
这两种写作方式有什么区别?我知道两者应该以同样的方式工作.
假设我们有:
课程Item:
public class Item {
private Type type;
Item(Type type) {
this.type = type;
if (type == Type.PISTOL || type == Type.AR || type == Type.SNIPER_RIFLE) {
this = new Weapon(type);
}
}
}
Run Code Online (Sandbox Code Playgroud)
和类Weapon继承自Item:
public class Weapon extends Item {
Bullet.Type bulletType;
int fireRate;
public Weapon(Type type) {
this.type = type;
}
}
Run Code Online (Sandbox Code Playgroud)
它从某个地方调用,如:
Item item = new Item(Item.Type.PISTOL);
Run Code Online (Sandbox Code Playgroud)
我实际上知道this在Java中不可分配,但我想知道如何解决这种情况.
如果它的类型合适,我想分配item新的Weapon.
我需要将值分配给线性,但是当我检查它时,结果是错误的。表达式1/exp( 2.30258509299 * (abs(dB)/20) )结果为0,063095734448(是正确值),但线性为-3,6854775808e + 4863,n为1,805186914e-307。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
procedure OnCreate(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.OnCreate;
var dB: integer;
linear: extended;
n: Double;
begin
dB := -24;
linear := 1/exp( 2.30258509299 * (abs(dB)/20) );
n := 0.063095734448;
showmessage(inttostr(db));
end;
end.
Run Code Online (Sandbox Code Playgroud)
我在做什么错了,如何获得正确的价值?
注意:为了评估表达式,我使用了调试器的“评估/修改”命令。