问题列表 - 第42913页

基本的C编程问题

我刚开始学习C而且它的速度很慢......我想写一个程序,它接受一个整数参数并返回它的加倍值(也就是取整数,乘以2,printf那个值).

我故意不想使用scanf函数.这是我到目前为止所做的以及没有编译的内容......

#include <stdio.h>

int main(int index)
{
    if (!(index)) {
        printf("No index given");
        return 1;
    }
    a = index*2;
    printf("Mult by 2 %d",a);

    return 0;

}
Run Code Online (Sandbox Code Playgroud)

所以基本上当程序执行时我想提供索引整数.所以,在cygwin中,我会写类似的东西./a 10,10会被存储到索引变量中.另外,我想编程返回"No index given"并在没有提供索引值的情况下退出...

有人在乎帮助我做错了吗?

编辑:

此代码在编译时返回1错误,并基于@James的帮助:

#include <stdio.h>

int main(int 1, char index)
{
    int index, a;
    if (!(index)) {
        printf("No index given");
        return 1;
    }
    a = index*2;
    printf("Mult by 2 %d",a);

    return 0;

}
Run Code Online (Sandbox Code Playgroud)

编辑2:考虑一个更简单的程序,其中只取一个值并回显(如下所示)

#include <stdio.h>

int main(int argc, char* argv[])
{
    int index;
    index = argv[1]; …
Run Code Online (Sandbox Code Playgroud)

c

0
推荐指数
1
解决办法
881
查看次数

solr搜索结果中的字段值为1或true

我有一个字段在Solr的schema.xml中被索引为字符串,该字段来自mysql数据库中的boolean(tinyint)列.

在查询中,我使用1搜索此字段.但是没有任何更改,此查询无法返回正确的结果.在我使用true而不是1之后,它再次起作用.现在它再次出错但是真的没问题1.

这里的确切问题是什么?我是否需要将schema.yml中的字段类型更改为整数?

先感谢您.

lucene solr

3
推荐指数
1
解决办法
3705
查看次数

java.lang.OutOfMemoryError:位图大小超过VM预算

我试图将我的应用程序的布局从纵向更改为横向,反之亦然.但是如果我经常这样做或不止一次,那么我的应用程序有时会崩溃.下面是错误日志.请建议可以做些什么?

 01-06 09:52:27.787: ERROR/dalvikvm-heap(17473): 1550532-byte external allocation too large for this process. 01-06 09:52:27.787: ERROR/dalvikvm(17473): Out of memory: Heap Size=6471KB, Allocated=4075KB, Bitmap Size=9564KB 
 01-06 09:52:27.787: ERROR/(17473): VM won't let us allocate 1550532 bytes 
 01-06 09:52:27.798: DEBUG/skia(17473): --- decoder->decode returned false
 01-06 09:52:27.798: DEBUG/AndroidRuntime(17473): Shutting down VM
 01-06 09:52:27.798: WARN/dalvikvm(17473): threadid=3: thread exiting with uncaught exception (group=0x4001e390)
 01-06 09:52:27.807: ERROR/AndroidRuntime(17473): Uncaught handler: thread main exiting due to uncaught exception
 01-06 09:52:27.857: ERROR/AndroidRuntime(17473): java.lang.RuntimeException: Unable to start activity ComponentInfo{}: android.view.InflateException: Binary XML …
Run Code Online (Sandbox Code Playgroud)

android memory-leaks

25
推荐指数
4
解决办法
4万
查看次数

最大化系统托盘中的应用程序?

我写了一个小的WPF应用程序,当'关闭'最小化到系统托盘(客户要求).双击弹出它,或右键单击提供上下文菜单退出.

但是如果应用程序被最小化,并且用户导航到Start-> All Programs-> The Application,它将启动一个新实例.

如果用户执行此操作而不是启动新实例,我需要做什么(在C#中)才能让应用程序最大化正在运行的实例?

谢谢!

c# wpf system-tray application-singleton

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

使用RavenDB会话将Ninject问题绑定到MVC3中的常量值

我已经看到了许多使用ASP.NET MVC配置Ninject的不同方法,但是随着MVC框架的每个版本的发布,实现似乎都有所改变.我正在尝试将RavenDB会话注入我的存储库.这就是我所拥有的几乎可以工作的东西.

public class MvcApplication : NinjectHttpApplication
{
    ...

    protected override void OnApplicationStarted()
    {
        base.OnApplicationStarted();

        AreaRegistration.RegisterAllAreas();

        RegisterGlobalFilters(GlobalFilters.Filters);
        RegisterRoutes(RouteTable.Routes);
    }

    protected override IKernel CreateKernel()
    {
        return new StandardKernel(new MyNinjectModule());
    }

    public static IDocumentSession CurrentSession
    {
        get { return (IDocumentSession)HttpContext.Current.Items[RavenSessionKey]; }
    }
    ...
}

public class MyNinjectModule : NinjectModule
{
    public override void Load()
    {
        Bind<IUserRepository>().To<UserRepository>();
        Bind<IDocumentSession>().ToConstant(MvcApplication.CurrentSession);
    }
}
Run Code Online (Sandbox Code Playgroud)

当它尝试解析IDocumentSession时,我收到以下错误.

Error activating IDocumentSession using binding from IDocumentSession to constant value
Provider returned null.
Activation path:
  3) Injection of dependency IDocumentSession into parameter …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc ninject ravendb

3
推荐指数
1
解决办法
1977
查看次数

如何使用VC++访问以太网端口?不使用套接字

我是以太网编程的初学者,我想访问以太网端口并向/从其发送/接收数据包.我想过使用CIM_EthernetPort类,但不知道怎么做.请帮忙.我必须编写一个程序来将数据发送到嵌入式系统.

mfc raw-ethernet visual-studio visual-c++

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

使用线程时如何解决错误?

我在使用NSThread时在控制台中有以下错误信息"尝试从主线程或网络线程以外的线程获取Web锁定.这可能是从辅助线程调用UIKit的结果.现在崩溃......"

我在这里提交了示例代码

- (void)viewDidLoad {

    appDeleg = (NewAshley_MedisonAppDelegate *)[[UIApplication sharedApplication] delegate];
    [[self tblView1] setRowHeight:80.0];
    [super viewDidLoad];
    self.title = @"Under Ground";


    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    [NSThread detachNewThreadSelector:@selector(CallParser) toTarget:self withObject:nil];

}

-(void)CallParser {


    Parsing *parsing = [[Parsing alloc] init];
    [parsing DownloadAndParseUnderground];

    [parsing release];
    [self Update_View];
    //[myIndicator stopAnimating];
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;




}
Run Code Online (Sandbox Code Playgroud)

这里的"DownloadAndParseUnderground"是从rss feed中下载数据的方法

-(void) Update_View{


    [self.tblView1 reloadData];
}
Run Code Online (Sandbox Code Playgroud)

当调用Update_View方法时,tableView重载数据并在cellForRowAtIndexPath中创建错误而不显示自定义单元格

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {


    static NSString *CellIdentifier = @"Cell";

    CustomTableviewCell *cell = (CustomTableviewCell *) [tblView1 dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == …
Run Code Online (Sandbox Code Playgroud)

iphone xcode ios4 ios

8
推荐指数
1
解决办法
1387
查看次数

当T是值类型时,更快的方式从String转换为泛型类型?

有没有人知道VB中从字符串到T限制为valuetype(Of T as Structure)的泛型类型的快速方式,当我知道T将始终是某种数字类型?

这对我来说太慢了:

Return DirectCast(Convert.ChangeType(myStr, GetType(T)), T)
Run Code Online (Sandbox Code Playgroud)

但它似乎是从String- > 获得唯一理智的方法T.我已经尝试使用Reflector看看它是如何Convert.ChangeType工作的,虽然我可以通过该代码的黑客版本从String转换为给定的数字类型,但我不知道如何将该类型重新插入,T以便可以返回.

我将添加我所看到的速度惩罚的一部分(在定时循环中)是因为返回值被赋值给一个Nullable(Of T)值.如果我强烈键入我的类为特定的数字类型(即UInt16),那么我可以大大提高性能,但是然后需要为我使用的每个数字类型复制该类.

如果T在通用方法/类中处理转换器时,它几乎是好的.也许有,我忘记了它的存在?


结论:
测试下面提供的三个实现和我原来的DirectCast/ChangeType表单,@ peenut使用预准备委托Parse从基本类型获取方法的方法有效.但是,没有进行错误检查,因此实现者需要记住只将其用于具有Parse可用方法的valuetype .或者扩展下面的内容来进行错误检查.

所有运行都在运行Windows Server 2003 R2和4GB RAM的32位系统上完成.每次"运行"是要测试的方法的1,000,000次执行(ops),使用StopWatch计时并以毫秒为单位报告.

原文DirectCast(Convert.ChangeType(myStr, GetType(T)), T):

1000000 ops: 597ms
Average of 1000000 ops over 10 runs: 472ms
Average of 1000000 ops over 10 runs: 458ms
Average of 1000000 ops over 10 runs: …
Run Code Online (Sandbox Code Playgroud)

vb.net

9
推荐指数
1
解决办法
5409
查看次数

SQL中的GROUP BY /聚合函数混淆

我需要一些帮助来理顺一些东西,我知道这是一个非常容易的简单问题,但它在SQL中稍微让我感到困惑.

此SQL查询在Oracle中引发"非GROUP BY表达式"错误.我理解为什么,正如我所知,一旦我按元组的属性进行分组,我就再也无法访问任何其他属性了.

SELECT * 
FROM order_details 
GROUP BY order_no
Run Code Online (Sandbox Code Playgroud)

不过这个确实有效

SELECT SUM(order_price)
FROM order_details
GROUP BY order_no
Run Code Online (Sandbox Code Playgroud)

只是具体我对此的理解....假设每个订单的order_details中有多个元组,一旦我按照order_no对元组进行分组,我仍然可以访问组中每个元组的order_price属性,但只使用聚合函数?

换句话说,在SELECT子句中使用的聚合函数能够深入到组中以查看"隐藏"属性,其中简单地使用"SELECT order_no"会抛出错误?

sql oracle

41
推荐指数
1
解决办法
3万
查看次数

在 Eclipse 中自动生成 getter 和 setter 的注释

Eclipse 可以选择从各自的变量生成 getter 和 setter。是否有一个选项或设置可以让我生成 getter 和 setter 的注释?

例如如果我的变量名称是

protected boolean isActive;
Run Code Online (Sandbox Code Playgroud)

然后,当我为此生成 getter 时,我是否也可以获得自动生成的注释块,如下所示 -

/**
 * Gets the value of the isActive property.
 * 
 * @return
 *     possible object is
 *     {@link Boolean }
 *     
 */
public Boolean getIsActive() {
    return isActive;
}
Run Code Online (Sandbox Code Playgroud)

如果这件事是可能的,那就太好了。另外评论区可以自定义吗?

java eclipse ide comments getter-setter

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