喜欢:
<img src="http://www.google.com/intl/en_ALL/images/srpr/logo1w.png">
Run Code Online (Sandbox Code Playgroud)
我想得到logo1w.png文件大小7.3kb
怎么实现呢?
假设我有一个可变函数foo(int tmp, ...),当调用foo函数时,我需要知道有多少个参数.我知道有两种方法可以找出有多少参数:
在调用foo时使用最后一个参数,比如-1,所以你的函数调用将是这样的:foo(tmp, 1, 2, 9, -1)当你在foo内部并且va_arg调用返回-1时你知道你已经读取了所有的函数参数
在foo中再添加一个参数,程序员将拥有参数总数,因此你可以像这样调用foo:foo(tmp, 5, 1, 2, 3, 4, 5)或者foo(tmp, 2, 7, 8)
我曾经遵循第一种方式,曾经有过以下错误.随着代码:
expr_of_type(expr, boolexpr_e, newtable_e, nil_e, -1)
Run Code Online (Sandbox Code Playgroud)
其中expr_of_type是一个可变参数函数,并检查expr(第一个参数)是否是以下类型之一(boolexpr_e或new_table_e或nil_e具有所有类型的枚举类型).我一个人意外地写道:
expr_of_type(expr, boolexpr_e, newtable_e, nil_e -1)
Run Code Online (Sandbox Code Playgroud)
我忘记了nil_e和-1之间的逗号,因为nil_e有一个枚举类型,nil_e - 1是一个有效的表达式,因为nil_e不是0,当试图获取expr_of_type参数时,给定的变量函数没有找到-1作为最后一个参数继续搜索创建一个花了我一些时间才发现的bug.
我也没有找到第二种方式,因为当从可变参数函数中添加或删除一个参数时,您需要更改包含总参数数量的参数.
在寻找更好的方法来使用/创建可变参数函数时,我找到了可变的宏,它可以解决我在使用第一种方式时遇到的错误.但是可变参数宏可用于C99标准.我一直在寻找一种在C89中使用/创建可变参数函数的更好方法.有任何想法吗?
我需要查找给定月份和给定年份的所有周末日期.
例如:对于01(月),2010(年),输出应为:2,3,9,10,16,17,23,24,30,31,所有周末日期.
我正在学习cakePHP 1.26.
我有一个控制器,它有两个功能.
我想让$ myVariable成为一个全局变量,这样控制器中的两个函数都可以共享它,但我不确定这是否是在cakePHP中声明全局变量的最佳方法:
class TestingController extends AppController {
var $myVariable="hi there";
function hello(){
if($newUser){echo $myVariable;}
}
function world(){
if($newUser=="old"){$myVariable="hi my friends";}
}
}
Run Code Online (Sandbox Code Playgroud)
如果可以,请帮忙.
编辑原因:
你好Aircule,
我已经改变了一些代码并遵循了你的建议,但myVariable的值根本没有改变:
class TestingController extends AppController {
var $myVariable="hi there";
function hello(){
echo $this->myVariable;
}
function world(){
$this->myVariable="hi my friends";
}
function whatValue(){
echo $this->myVariable; // still output "hi there"
}
}
Run Code Online (Sandbox Code Playgroud) 当我阅读Pragmatic Bookshelf的书籍时,它具有以下格式:
http://img210.imageshack.us/img210/2965/screenshot20100717at121.png
这应该是一个相当简单的问题,但我无法在网上找到一个可靠的答案.我试图在同一个表中插入多行,但只有一个语句.我在网上看到的最流行的是以下内容,但我读过它只适用于SQL Server 2008:
INSERT INTO Table (Name, Location) VALUES
('Name1', 'Location1'),
('Name2', 'Location2'),
('Name3', 'Location3'), etc...
Run Code Online (Sandbox Code Playgroud)
我更喜欢这种方法,如果它适用于SQL Server 2005,但我不认为它会.另外一个选项,从我读过的,与INSION之后的UNION ALL后面的SELECT语句有关,这看起来很笨拙.有谁知道在2005年做到这一点的最佳语法?
谢谢.
我正在尝试计算Scala中图像的平均颜色,其中"average"被定义为redSum/numpixels,greenSum/numpixels,blueSum/numpixels.
这是我用来计算图像矩形区域(Raster)中的平均颜色的代码.
// A raster is an abstraction of a piece of an image and the underlying
// pixel data.
// For instance, we can get a raster than is of the upper left twenty
// pixel square of an image
def calculateColorFromRaster(raster:Raster): Color = {
var redSum = 0
var greenSum = 0
var blueSum = 0
val minX = raster.getMinX()
val minY = raster.getMinY()
val height = raster.getHeight()
val width = raster.getWidth()
val numPixels = height * width …Run Code Online (Sandbox Code Playgroud) 我有一个包含2个表的数据库:
项目具有ID密钥
ItemDependencies有两列:ItemId和DependsOnItemId
我把它转换成一个集合:
IEnumerable<Item> items = GetItems();
Run Code Online (Sandbox Code Playgroud)
每个项目都有一个:Dependencies属性,它是一个
List<Item>
Run Code Online (Sandbox Code Playgroud)
所以我想过滤初始项目列表:
给定一个项目,我想要一个该项目的列表以及递归依赖此项目的所有项目.
给定一个项目,我想要一个该项目的列表以及它所依赖的所有其他项目(也是递归的).
在C#,LINQ或其他任何可以解决这个问题的方法中,最好的方法是什么.
mycode的:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TabHost tabHost = (TabHost) findViewById(R.id.tabhost);
// LocalActivityManager mLocalActivityManager = new LocalActivityManager(this, false);
tabHost.setup();
TabSpec tabSpecCheckIn = tabHost.newTabSpec(getResources().getText(R.string.button_check_in).toString());
tabSpecCheckIn.setIndicator(getResources().getText(R.string.button_check_in).toString(), getResources().getDrawable(android.R.drawable.star_off));
tabSpecCheckIn.setContent(R.id.check_in);
tabHost.addTab(tabSpecCheckIn);
TabSpec tabSpecReview = tabHost.newTabSpec(getResources().getText(R.string.button_review).toString());
tabSpecReview.setIndicator(getResources().getText(R.string.button_review).toString(), getResources().getDrawable(android.R.drawable.star_off));
tabSpecReview.setContent(R.id.review);
tabHost.addTab(tabSpecReview);
TabSpec tabSpecMyCircles = tabHost.newTabSpec(getResources().getText(R.string.button_my_circles).toString());
tabSpecMyCircles.setIndicator(getResources().getText(R.string.button_my_circles).toString(), getResources().getDrawable(android.R.drawable.star_off));
tabSpecMyCircles.setContent(R.id.my_circle);
tabHost.addTab(tabSpecMyCircles);
TabSpec tabSpecMySettings = tabHost.newTabSpec(getResources().getText(R.string.button_settings).toString());
tabSpecMySettings.setIndicator(getResources().getText(R.string.button_settings).toString(), getResources().getDrawable(android.R.drawable.star_off));
tabSpecMySettings.setContent(new Intent(this,CheckInActivity.class));
tabHost.addTab(tabSpecMySettings);
tabHost.setCurrentTab(0);
}
}
Run Code Online (Sandbox Code Playgroud)
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabHost android:id="@+id/tabhost"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<TabWidget android:layout_width="fill_parent" …Run Code Online (Sandbox Code Playgroud) android ×1
c ×1
c# ×1
c89 ×1
cakephp ×1
cakephp-1.2 ×1
collections ×1
date ×1
enums ×1
exception ×1
formatting ×1
ienumerable ×1
insert ×1
java ×1
javascript ×1
jquery ×1
latex ×1
linq ×1
oop ×1
php ×1
random ×1
scala ×1
sql ×1
tree ×1
weekend ×1