在我结束第一次循环后,我继续遇到段故障,而对于我的生活,我不知道为什么.我正在扫描的文件只有18行中的18个字符串.我认为问题是我正在使用名为picks的双指针的方式,但我不确切知道为什么.我只是试图扫描长度小于15个字符的字符串,所以我没有看到问题.有人可以请帮助.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_LENGTH 100
int main( int argc,char *argv[] )
{
char* string = malloc( 15*sizeof(char) );
char** picks = malloc(15*sizeof(char*));
FILE* pick_file = fopen( argv[l], "r" );
int num_picks;
for( num_picks=0 ; fgets( string, MAX_LENGTH, pick_file ) != NULL ; num_picks++ )
{
scanf( "%s", picks+num_picks );
}
//this is where i seg fault
int x;
for(x=0; x<num_picks;x++)
printf("s\n", picks+x);
}
Run Code Online (Sandbox Code Playgroud) 我希望图层从绿色开始,然后慢慢变为黄色,橙色,最后是红色.我该怎么做呢?
CAShapeLayer *layer = [CAShapeLayer layer];
[layer setStrokeColor:[UIColor greenColor].CGColor];
[layer setLineWidth:5.0f];
[layer setFillColor:[UIColor clearColor].CGColor];
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:button.bounds cornerRadius:10.0f];
layer.path = path.CGPath;
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
animation.fromValue = [NSNumber numberWithFloat:0.0f];
animation.toValue = [NSNumber numberWithFloat:1.0f];
animation.duration = 4.0f;
[layer addAnimation:animation forKey:@"myStroke"];
[button.layer addSublayer:layer];
Run Code Online (Sandbox Code Playgroud) 您可以修改此BNF语法以始终包含奇数个狗吗?
<pets> ::= <pets> <pet> | <pet>
<pet> ::= dog | cat
Run Code Online (Sandbox Code Playgroud)
“宠物”的示例:
dog cat
cat dog
dog dog dog
dog dog cat cat dog
dog cat dog dog
Run Code Online (Sandbox Code Playgroud)
不是“宠物”的示例:
cat
dog cat dog
cat cat
Run Code Online (Sandbox Code Playgroud) 我认为如果一个进程从唯一的用户ID中选择余额并尝试执行插入,则会错误地更新余额,但是另一个进程会在此之前读取余额.我该如何解决?
CREATE OR REPLACE FUNCTION incBalance(INTEGER, BIGINT) RETURNS void AS $$
DECLARE
balanceRecord record;
newBalance bigint;
BEGIN
FOR balanceRecord IN
SELECT balance FROM users WHERE userid = $1
LOOP
newBalance := balanceRecord.balance + $2;
UPDATE users SET balance = newBalance WHERE userid = $1;
END LOOP;
RETURN;
END;
$$ LANGUAGE plpgsql;
Run Code Online (Sandbox Code Playgroud) class C:
def __init__(self,n,x):
self.n = n
self.x = x
a = C('a',1)
b = C('b',2)
c = C('c',3)
classList = [b,a,c]
for q in classList: print q.n,
classList.sort(lambda a,b: long(a.x - b.x))
for q in classList: print q.n,
Run Code Online (Sandbox Code Playgroud)
运行上面的代码会得到错误TypeError: comparison function must return int, not long.是否有另一种干净的方法来通过某些类变量对类对象进行排序?
每次客户端连接到服务器时,我都会收到提示输入PEM密码短语.我想只在服务器启动时输入它,而不必再次输入它.Twisted Matrix框架只需要启动时的密码短语,为什么不gevent?或者我使用gevent错了?如果我使用不需要PEM密码的证书,下面的代码工作正常,但我想使用带密码短语的证书.
from gevent.server import StreamServer
from gevent.pool import Pool
from gevent import monkey
class SocketPool(object):
def __init__(self): self.pool = Pool(1000)
def listen(self, socket):
while True:
line = socket.recv(1024)
if not line: break
print line
socket.close()
break
def add_handler(self, socket, address):
print "connection made:", address
if self.pool.full(): raise Exception("At maximum pool size")
else: self.pool.spawn(self.listen, socket)
def shutdown(self): self.pool.kill()
monkey.patch_all()
sockPool = SocketPool()
server = StreamServer(('', 5000), sockPool.add_handler, keyfile='key.pem', certfile='cert.pem')
server.serve_forever()
Run Code Online (Sandbox Code Playgroud) 您好我是在尝试学习python,在C++中从stdin读取字符串我就是这么做的
string str;
while (cin>>str)
do_something(str)
Run Code Online (Sandbox Code Playgroud)
但在python中,我必须使用
line = raw_input()
Run Code Online (Sandbox Code Playgroud)
然后
x = line.split()
Run Code Online (Sandbox Code Playgroud)
然后我必须遍历列表x来访问每个str do_something(str)
这似乎是很多代码只是为了让每个字符串由空格或空格分隔所以我的问题是,有更简单的方法吗?
<html>
<div class="button">
<input type="button" onclick="method1();" id="1" value="Button1"/>
</div>
<div class="button">
<input type="button" onclick="method2();" id="2" value="Button2"/>
</div>
</html>
Run Code Online (Sandbox Code Playgroud)
无需修改Html,我可以将两个按钮组合成一个按钮吗?单击该按钮时,是否可以调用这两个方法?可以用Javascript/JQuery完成吗?如果是这样,你会怎么做?
换句话说,我可以隐藏一个按钮并在不更改html的情况下触发两个方法.
我正在第一次尝试编写像Zynga Poker这样的iOS/Android扑克应用程序,我必须同时处理多达300,000个客户端连接,而且随着我的用户群增长,我还要做更多.客户将连接到未填充的房间,其中5-9个玩家与其他玩家互动,并且能够互相发送消息.我做了很多研究,似乎Twisted Matrix是事实上的标准,但我对gevent也很感兴趣,因为它使用协程而不是回调来处理异步编程.但令我担心的一件事是来自这个网站的程序员,http://news.ycombinator.com/item?id = 2288081写了这个
"这就是为什么我不明白为什么许多高端的实时网络创业公司(如Convore),仍然使用劣质解决方案,如Python eventlib或gevent,它们最多让它们处理数百到数千个客户端."
这是真的?所以我在使用哪个框架之间徘徊.或者那里有更好的东西吗?是300k连接要求python的大部分?如果是,我愿意用java或C++来做服务器,但我宁愿使用python.
我想做这样的事情.
PREPARE addFriend(INTEGER, INTEGER) AS
INSERT INTO friendRelation (u_id, friendid) VALUES ($1, $2),
INSERT INTO friendRelation (u_id, friendid) VALUES ($2, $1);
Run Code Online (Sandbox Code Playgroud)
我在文档中没有看到这一点,所以要么不能做,要么我做错了.如果你在准备好的语句中不能有2个查询,那么我还不知道postgres的其他功能可以做到这一点吗?
我有一个程序,只是一个大循环.我首先有一个空集.在for循环的每次迭代中,我需要查看并从集合中删除最小值.同样在每次迭代中,我可以添加0到8个值的任何值(值是随机的).我应该使用哪种内置Java数据结构?我考虑使用ArrayList进行冒泡排序,然后取出第一个索引.我正在寻找最快的算法来完成这项任务.
最初我在LoginViewController.m中有包含下面警告的文件,我忽略了它.代码工作正常.
warning: sending 'LoginViewController *' to parameter of incompatible type 'id<NSStreamDelegate>'
Run Code Online (Sandbox Code Playgroud)
但现在我将文件扩展名更改为.mm(LoginViewController.mm).现在我无法再构建项目了,因为这个错误.
Cannot initialize a parameter of type 'id<NSStreamDelegate>' with an lvalue of type 'LoginViewController *'
Run Code Online (Sandbox Code Playgroud)
怎么了?
我目前正在阅读算法的书,并遇到了稳定的匹配问题.一个问题浮现在脑海里,我很好奇,但这本书没有回答.在每个SMP中,总是可以有一对,每个最喜欢另一个?就像在经典的婚姻例子中一样.是否总有一对有一个女人和一个男人在哪里都排在彼此的首选?
algorithm ×2
gevent ×2
ios ×2
objective-c ×2
postgresql ×2
python ×2
sorting ×2
asynchronous ×1
atomic ×1
bnf ×1
c ×1
calayer ×1
cocoa-touch ×1
concurrency ×1
html ×1
java ×1
javascript ×1
jquery ×1
malloc ×1
parsing ×1
plpgsql ×1
proof ×1
protocols ×1
python-2.7 ×1
raw-input ×1
sql ×1
ssl ×1
stdin ×1
syntax ×1
twisted ×1