我读了一个char数组,scanf并想检查长度是否大于15.它只在有时工作.(如果不是我收到错误 - >核心转储.)
我的代码:
#include <stdio.h>
int checkArray(char string[], int length) {
int i;
for(i=0; string[i] != '\0'; i++);
if(i > length) {
return -1;
}
return 0;
}
int main ()
{
const int length = 15;
char x[15];
scanf("%s", x);
if(checkArray(x, length) == -1) {
printf("max. 15 chars!");
return 1;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试安装PECL包,我收到了这个错误.我不确定该怎么办,所以希望有人可以提供一些帮助:
# pecl install -f ssh2
WARNING: failed to download pecl.php.net/ssh2 within preferred state "stable", will instead download version 0.11.3, stability "beta"
downloading ssh2-0.11.3.tgz ...
Starting to download ssh2-0.11.3.tgz (23,062 bytes)
........done: 23,062 bytes
5 source files, building
running: phpize
Cannot find build files at '/usr/lib64/php/build'. Please check your PHP installation.
ERROR: `phpize' failed
Run Code Online (Sandbox Code Playgroud) 总结:有没有办法从文件中获取唯一的行数和出现次数比使用sort | uniq -c | sort -n?
详细信息:我经常sort | uniq -c | sort -n在进行日志分析时获取一般趋势,了解哪些日志条目显示最多/最少等.这大部分时间都有效 - 除非我处理的是一个非常大的日志文件大量重复(在这种情况下sort | uniq -c最终需要很长时间).
示例:我现在面临的具体情况是从"未参数化"的mysql bin日志中获取趋势,以找出哪些查询运行最多.对于一个百万条目的文件,我通过grep/sed组合来删除参数 - 产生大约150个独特的行 - 我花了大约3秒的grepping和sedding,以及大约15s的排序/ uniq'ing.
目前,我已经找到了一个简单的c ++程序来维护一个<line,count>的映射 - 它可以在不到一秒的时间内完成工作 - 但我想知道现有的实用程序是否已经存在.
当我尝试该命令时searchd,它显示:
using config file '/usr/local/etc/sphinx.conf'...
WARNING: compat_sphinxql_magics=1 is deprecated; please update your application and config
listening on all interfaces, port=9312
bind() failed on 0.0.0.0, retrying...
bind() failed on 0.0.0.0, retrying...
bind() failed on 0.0.0.0, retrying...
bind() failed on 0.0.0.0, retrying...
bind() failed on 0.0.0.0, retrying...
bind() failed on 0.0.0.0, retrying...
bind() failed on 0.0.0.0, retrying...
bind() failed on 0.0.0.0, retrying...
bind() failed on 0.0.0.0, retrying...
bind() failed on 0.0.0.0, retrying...
bind() failed on 0.0.0.0, retrying...
bind() failed on …Run Code Online (Sandbox Code Playgroud) 我的语法有两个令牌声明:
%token RP
%token ELSE
Run Code Online (Sandbox Code Playgroud)
而这两条规则:
Statement : IF LP Exp RP Statement;
Statement : IF LP Exp RP Statement ELSE Statement;
Run Code Online (Sandbox Code Playgroud)
根据我的理解,规则的优先级取决于其最后一个非终结符的优先级.因此,第一个规则具有RP优先级,第二个规则具有ELSE高于的优先级RP.以下是野牛的输出:
state 73
11 Statement: IF LP Exp RP Statement .
12 | IF LP Exp RP Statement . ELSE Statement
ELSE shift, and go to state 76
ELSE [reduce using rule 11 (Statement)]
$default reduce using rule 11 (Statement)
Run Code Online (Sandbox Code Playgroud)
这种冲突不应该通过转移解决,因为ELSE具有更高的优先级?
除了在C++中实现我自己的双向链表的学习方面的学术方面,当已经有std :: list时,实现我自己的双向链表是否有任何实际的现实优势?我能否为自己的某项任务提高效率,或者多年来std :: list已被提炼得如此之多以至于在大多数情况下它是双向链表的最佳实现?
我有这个代码:
unsigned short (*pixel_array)[SCREEN_HEIGHT] = get_ok_zone(mouse_mask);
unsigned short (*pixel_border)[2] = get_ok_zone_border(pixel_array);
Run Code Online (Sandbox Code Playgroud)
这让我可以访问这两个数据数组.
我需要以某种方式将这两个数组作为ONE参数传递给函数.
我不仅无法弄清楚如何传递它们,我无法弄清楚一旦我将它们放入函数中就能单独访问它们.
我一整天都在努力理解这一点,它似乎正在逃避我.
有人可以向我解释我需要做什么才能通过一个参数(可能在一个指针数组中)将这两个数组传递给一个函数,以及如何在函数内部访问它们?
编辑:我将参数(我唯一允许传递的参数)传递给Quartz Event Tap回调.
编辑2: @Kevin
我创建了结构:
struct array_stack {
unsigned short (*pixel_array)[SCREEN_HEIGHT];
unsigned short (*pixel_border)[2];
};
Run Code Online (Sandbox Code Playgroud)
然后,在我的int main()中,我有:
struct array_stack as = {get_ok_zone(mouse_mask), get_ok_zone_border(get_ok_zone(mouse_mask))};
CFRunLoopSourceRef runLoopSource;
CGEventMask event_mask;
event_mask = CGEventMaskBit(kCGEventMouseMoved) | CGEventMaskBit(kCGEventLeftMouseDragged) | CGEventMaskBit(kCGEventRightMouseDragged) | CGEventMaskBit(kCGEventOtherMouseDragged);
CGSetLocalEventsSuppressionInterval(0);
CFMachPortRef eventTap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, 0, event_mask, mouse_filter, as);
Run Code Online (Sandbox Code Playgroud)
(我传递了代码块底部的as最后一个参数CGEventTapCreate());
我收到错误passing struct array_stack to a parameter of incompatible type …
我正在使用 Rails 3.1.2 开发一个应用程序,但我找不到一些可以处理此版本的 Rails 上的错误/异常(如 404)的文档。
我尝试过类似的事情:
在应用程序控制器中
rescue_from ActiveRecord::RecordNotFound,ActionController::RoutingError,
ActionController::UnknownController, ActionController::UnknownAction, :NoMethodError, :with => :handle_exception
def handle_exception
render :template => 'error_pages/error'
end
environment/development.rb
config.consider_all_requests_local = false
Run Code Online (Sandbox Code Playgroud)
我在哪里可以找到解决方案?
提前致谢...
我试图了解jquery,并且无法解决问题.我有一个包含2个或更多表的页面,但我希望能够识别所有具有某个类的表(它们可能有超过1个类).一旦我有这个表/表,我想更新奇数/偶数行上的类.
这有效,但它会在所有表上设置类,无论它们是否具有tableData类.
$(function() {
if($("table").hasClass("tableData")) {
$("tr:odd").addClass("alt");
};
});
Run Code Online (Sandbox Code Playgroud)
这不起作用(我尝试过的其他版本也没有).
$(function() {
if($("table").hasClass("tableData")) (function() {
$(this).("tr:odd").addClass("alt");
});
});
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我很确定我可以用Java泛型来解决这个问题,所以我想问一下......假设我有一些类,每个类都实现了一个公共接口,在公共接口中有一个方法叫做getData,我想要制作通用.我遇到的问题是每个类都返回一个不同的对象类型,所以理想情况下我希望它们是通用的,然后在调用的实现类中getData,将它们转换回原始类型.如果我要转换Object为特定类型并返回特定类型,我可以看到它是如何工作的,但是我能用Generics完成相同的最终结果吗?
这里有一些伪代码来概述问题:
public ClassA implements interface x {
private CustomObjectA customObjectA;
private Map<DateTime, Map<String, CustomObjectA>> dataMap;
...
public Map<DateTime, Map<String, CustomObjectA>> getData() {
return this.dataMap;
}
}
public ClassB implements interface x {
private CustomObjectA customObjectB;
private Map<DateTime, Map<String, CustomObjectB>> dataMap;
...
public Map<DateTime, Map<String, CustomObjectB>> getData() {
return this.dataMap;
}
}
public interface x {
public Map<DateTime, Map<String, genericObject>> getData();
}
public ClassC {
public testGeneric(x objX) {
CustomObjectA cOA = objX.getData();
CustomObjectB …Run Code Online (Sandbox Code Playgroud)