问题列表 - 第23512页

如何从函数返回字符串文字

关于从函数返回字符串文字或字符串我总是很困惑.我被告知可能存在内存泄漏,因为您不知道何时会删除内存?

例如,在下面的代码中,如何实现foo()以使代码的输出为"Hello World"?

void foo (       )              // you can add parameters here.
{

}

int main ()
{
    char *c;
    foo (    );
    printf ("%s",c);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

另外,如果返回类型foo()不是无效,但你可以返回char*,它应该是什么?

c++ string return-type literals

7
推荐指数
2
解决办法
1万
查看次数

为什么JavaScript需要以";"开头?

我最近注意到,Web上的很多JavaScript文件都是;紧跟在评论部分之后开始的.

例如,这个jQuery插件的代码以:

/**
 * jQuery.ScrollTo
 * Copyright (c) 2007-2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 9/11/2008                                      
 .... skipping several lines for brevity...
 *
 * @desc Scroll on both axes, to different values
 * @example $('div').scrollTo( { top: 300, left:'+=200' }, { axis:'xy', offset:-20 } );
 */
;(function( $ ){
Run Code Online (Sandbox Code Playgroud)

为什么文件需要以;?开头?我也在服务器端JavaScript文件中看到了这种约定.

这样做的优点和缺点是什么?

javascript jquery jquery-plugins serverside-javascript

217
推荐指数
3
解决办法
7117
查看次数

使用NSScanner从最后一个字符实例扫描到字符串结尾

给定一个字符串,例如:"new/path - path/path/03 - filename.ext",如何使用NSScanner(或任何其他方法)将子字符串从最后一个"/"返回到字符串的末尾,即,"03 - filename.ext"?我一直试图开始的代码是:

while ([fileScanner isAtEnd] == NO){
    slashPresent = [fileScanner scanUpToString:@"/" intoString:NULL];
    if (slashPresent == YES) {
        [fileScanner scanString:@"/" intoString:NULL];
        lastPosition = [fileScanner scanLocation];
    }
    NSLog(@"fileScanner position: %d", [fileScanner scanLocation]);
    NSLog(@"lastPosition: %d", lastPosition);       
}
Run Code Online (Sandbox Code Playgroud)

...这会在扫描到字符串末尾后导致段错误!我不确定为什么这不起作用.想法?提前致谢!

cocoa objective-c

4
推荐指数
1
解决办法
1809
查看次数

将switch语句转换为更优雅的解决方案

我有一个9 x 9矩阵.(想想suduko).

   4 2 1 6 8 1 8 5 8 
   3 1 5 8 1 1 7 5 8 
   1 1 4 0 5 6 7 0 4 
   6 2 5 5 4 4 8 1 2 
   6 8 8 2 8 1 6 3 5 
   8 4 2 6 4 7 4 1 1 
   1 3 5 3 8 8 5 2 2 
   2 6 6 0 8 8 8 0 6 
   8 7 2 3 3 …
Run Code Online (Sandbox Code Playgroud)

c# matrix switch-statement

2
推荐指数
1
解决办法
396
查看次数

解释JAVA代码

我需要一些帮助来解释从第5行到第9行的含义.谢谢

  1. String words = "Rain Rain go away";

  2. String mutation1, mutation2, mutation3, mutation4;

  3. mutation1 = words.toUpperCase();

  4. System.out.println ("** " + mutation1 + " Nursery Rhyme **");

  5. mutation1 = words.concat ("\nCome again another day");

  6. mutation2 = "Johnny Johnny wants to play";

  7. mutation3 = mutation2.replace (mutation2.charAt(5), 'i');

  8. mutation4 = mutation3.substring (7, 27);

  9. System.out.print ("\'" + mutation1 + "\n" + mutation4 + "\'\n");

  10. System.out.println ("Title length: " + words.length());

java string mutation

-2
推荐指数
1
解决办法
646
查看次数

NHibernate.Bytecode.UnableToLoadProxyFactoryFactoryException

我在我的启动中设置了以下代码

IDictionary<string, string> properties = new Dictionary<string, string>();

properties.Add("connection.driver_class", "NHibernate.Driver.SqlClientDriver");
properties.Add("dialect", "NHibernate.Dialect.MsSql2005Dialect");
properties.Add("proxyfactory.factory_class", "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle");
properties.Add("connection.provider", "NHibernate.Connection.DriverConnectionProvider");
properties.Add("connection.connection_string", "Data Source=ZEUS;Initial Catalog=mydb;Persist Security Info=True;User ID=sa;Password=xxxxxxxx");
InPlaceConfigurationSource source = new InPlaceConfigurationSource();
source.Add(typeof(ActiveRecordBase), (IDictionary<string, string>) properties);

Assembly asm = Assembly.Load("Repository");

Castle.ActiveRecord.ActiveRecordStarter.Initialize(asm, source);
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

failed: NHibernate.Bytecode.UnableToLoadProxyFactoryFactoryException : Unable to load type 'NNHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle' during configuration of proxy factory class.

可能的原因是:

  • 未部署NHibernate.Bytecode提供程序程序集.
  • 用于初始化session-factory部分的"proxyfactory.factory_class"属性的typeName格式不正确.

我已阅读并阅读我正在参考列出的所有大会,我完全不知道接下来要尝试什么.

Castle.ActiveRecord.dll
Castle.DynamicProxy2.dll
Iesi.Collections.dll
log4net.dll
NHibernate.dll
NHibernate.ByteCode.Castle.dll
Castle.Core.dll.

我100%确定装配在箱子里.有人有主意吗?

nhibernate castle-activerecord

4
推荐指数
1
解决办法
4612
查看次数

如果我XOR 2号码,如果数字相同,我只能获得相同的结果吗?

例如,假设我有x XOR y = y XOR x = z.有可能有类似的东西a XOR b = z吗?

boolean-logic xor

4
推荐指数
2
解决办法
8825
查看次数

Rails脚本/生成错误

我在我的ubuntu 8.10桌面上安装了ruby on rails.脚本/生成出现了这个错误.

# script/generate
undefined method `index' for #<Enumerator: "Rails Info:":each_line>
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

谢谢你的帮助,zeem

ruby-on-rails

5
推荐指数
1
解决办法
215
查看次数

你怎么知道javascript中的对象是否是JSON?

我怎么知道变量是JSON还是其他东西?是否有一个JQuery函数或我可以用来解决这个问题的东西?

javascript jquery json

14
推荐指数
3
解决办法
2万
查看次数

从JQuery发布到WCF服务

我有一个WCF服务(称为"myservice.svc"),它接收来自用户的消息并将其保存到数据库.它以数字的形式向用户返回响应.此操作如下所示:

[OperationContract]
[WebGet]
public string SubmitMessage(string message)
{
  try
  {
    // SAVE TO DATABASE
    return "1";
  }
  catch (Exception ex)
  {
    return "0";
  }
}
Run Code Online (Sandbox Code Playgroud)

我想从一些JQuery调用此操作.我正在使用此处显示的方法:

$.getJSON(
  "/services/myService.svc",
  {message:"some text"},
  function (data) {
    alert("success");                
  }
);
Run Code Online (Sandbox Code Playgroud)

奇怪的是,永远不会显示"成功"警报.另外,我在我的WCF服务中设置了一个断点,它永远不会被触发.我究竟做错了什么?

谢谢

wcf jquery

2
推荐指数
1
解决办法
1228
查看次数