我正在尝试使用C编程将二进制数据写入.bin文件,然后迭代编写从0000到FFFF.我想我会使用带有'wb'标签的fopen,然后能够写二进制数据,但我不确定如何使用C从0000迭代到FFFF.感谢任何帮助.
这是我现在的代码:
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *f = fopen("binary.bin", "wb");
unsigned long i;
//if(f == NULL) { ...error handling... }
for(i = 0x0000; i <= 0xFFFF; i++){
// Write something to the file, e.g. the 16-bit (2 byte) value of "i"
unsigned short someData = i;
fwrite(&someData, 1, 2, f);
}
fclose(f);
return 0;
//printf("Hello World\n");
getchar();
}
Run Code Online (Sandbox Code Playgroud)
这将输出00 00 01 00 02 00 ...
这是我现在的问题.这不应该读出00 00 00 01 00 02 ......开头不应该有额外的'00'吗?
此外,我一直在试图看看如何复制它并扩展它因此使它0000 0000 0001 0001等?[更新:我刚刚复制了fwrite行并再次执行了它解决了这个问题]
在Windows性能监视器工具中._Total和选择计数器实例时有什么区别?
我的iPhone应用程序中有一个简单的屏幕,我希望在屏幕底部有一个320x100的矩形来捕捉触摸.这是我的代码touchesBegan:withEvent
:
for (UITouch *touch in touches) {
CGPoint touchPoint = [touch locationInView:self.view];
NSLog(@"touch @ %f, %f", touchPoint.x, touchPoint.y);
// build a rectangle where we want to capture a URL tap
CGRect rectangle = CGRectMake(0, 480, 320, 100);
NSLog(@"midX, midY = %f, %f", CGRectGetMidX(rectangle), CGRectGetMidY(rectangle));
// check to see if they tapped the URL
if (CGRectContainsPoint(rectangle, touchPoint)) {
NSLog(@"You touched inside the rectangle.");
}
}
Run Code Online (Sandbox Code Playgroud)
现在这段代码无法正常工作......从矩形中点开始的日志显示我的矩形是在内置的midX, midY = 160.000000, 530.000000
.根据CGPoint文档,原点(0, 480)
是左下角,但这就像原点是左上角.
当我将矩形的原点更改为0,380时,一切都按预期工作.也许我今天早上没有适当的咖啡因,但为什么我看到文档和执行之间的这种差异?
void printLine(const wchar_t* str, ...)
{
// have to do something to make it work
wchar_t buffer[2048];
_snwprintf(buffer, 2047, ????);
// work with buffer
}
printLine(L"%d", 123);
Run Code Online (Sandbox Code Playgroud)
我试过了
va_list vl;
va_start(vl,str);
Run Code Online (Sandbox Code Playgroud)
这样的事情,但我找不到解决方案.
我可以以某种方式从Tortoise SVN导出设置(我的意思是Tortoise SVN客户端设置,而不是颠覆).我必须为整个开发团队安装Tortoise SVN,并且不想多次设置客户端.我试图在Google上搜索但没有发现任何内容.
谢谢
好吧,我试图读取一个看起来像这样的文本文件:
FTFFFTTFFTFT
3054 FTFFFTTFFTFT
4674 FTFTFFTTTFTF
......等
当我正在阅读它时,一切都编译并且工作得非常好,将所有内容放入这样的数组中:
studentID [0] = 3054
studentID [1] = 4674
......等
studentAnswers [0] = FTFFFTTFFTFT
studentAnswers [1] = FTFTFFTTTFTF
但是,如果studentID具有前导零或尾随零,当我使用System.out.println();打印它时,它会删除前导零和尾随零!我觉得这很简单,我需要复制数组或其他东西.谢谢 :)
以下是我的代码:
public static String[] getData() throws IOException {
int total = 0;
int[] studentID = new int[127];
String[] studentAnswers = new String[127];
String line = reader.readLine();
String answerKey = line;
StringTokenizer tokens;
while((line = reader.readLine()) != null) {
tokens = new StringTokenizer(line);
studentID[total] = Integer.parseInt(tokens.nextToken());
studentAnswers[total] = tokens.nextToken();
System.out.println(total + " " +studentID[total]); …
Run Code Online (Sandbox Code Playgroud) 我有一个包含100k文本文件的文件夹.我想把超过20行的文件放在另一个文件夹中.我怎么在python中这样做?我使用了os.listdir,但当然没有足够的内存来将文件名加载到内存中.有没有办法一次获得100个文件名?
这是我的代码:
import os
import shutil
dir = '/somedir/'
def file_len(fname):
f = open(fname,'r')
for i, l in enumerate(f):
pass
f.close()
return i + 1
filenames = os.listdir(dir+'labels/')
i = 0
for filename in filenames:
flen = file_len(dir+'labels/'+filename)
print flen
if flen > 15:
i = i+1
shutil.copyfile(dir+'originals/'+filename[:-5], dir+'filteredOrigs/'+filename[:-5])
print i
Run Code Online (Sandbox Code Playgroud)
并输出:
Traceback (most recent call last):
File "filterimage.py", line 13, in <module>
filenames = os.listdir(dir+'labels/')
OSError: [Errno 12] Cannot allocate memory: '/somedir/'
Run Code Online (Sandbox Code Playgroud)
这是修改后的脚本:
import os
import shutil
import glob …
Run Code Online (Sandbox Code Playgroud) 我使用CURL来检查是否存在URL(HEAD请求),但是当我测试它时www.google.com
,它会将我重定向到www.google.co.uk
- 可能是因为我的服务器是基于英国的.
有没有办法阻止这种情况发生?我不想删除该CURLOPT_FOLLOWLOCATION
选项,因为这对301重定向等有用.
我的部分代码如下;
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_FORBID_REUSE, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 4);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
$output = curl_exec($ch);
// get data
$data = curl_getinfo($ch);
Run Code Online (Sandbox Code Playgroud)
$data['url']
含有www.google.co.uk
当我设置$url
为www.google.com
我正在将NHibernate用于ORM,并将许多实体的加载合并为一个大查询.
我实际上正在加载一个单词字典,大约500K条目,每个单词与其他单词相关.在后台运行加载过程在我们的应用程序中可能非常棘手,因为我们必须手动加载未按时加载的条目,因为任何时候都可以询问任何单词.我们唯一的要求是尽可能快地加载所有数据.我也尝试过使用无状态会话,但是有一个例外,即无状态会话无法获取集合(出于某种原因,可能与无状态会话没有缓存的事实有关吗?)
问题是虽然SQLServer中的查询时间不超过25秒,但ICriteria.List()需要3分钟以上.
我使用NHProf来描述加载过程,并发现实体的创建是一项代价高昂的事情,它占用了NHibernate的大部分加载时间.
有什么办法可以减少这种延迟吗?内存分配是昂贵的,还是数据的"填充"?
谢谢!
我有PHP脚本从邮箱中获取邮件.我使用imap_search函数:
$emails = imap_search($mbox, 'UNSEEN');
有没有办法限制返回的消息数量.现在在巨大的邮箱上我得到5000条消息.我只希望按日期排序的前20名.
有没有办法做到这一点?
谢谢.
c ×2
php ×2
arrays ×1
binary ×1
c++ ×1
curl ×1
dns ×1
email ×1
file-io ×1
imap ×1
iphone ×1
java ×1
libcurl ×1
nhibernate ×1
objective-c ×1
orm ×1
performance ×1
python ×1
tortoisesvn ×1
windows ×1