【发布时间】:2014-08-27 09:30:51
【问题描述】:
我有一个用 C 语言在 Linux 中编写的程序,它在 Linux 平台上运行良好,但在 Windows 中却无法运行。它使用代码块(mingw32-gcc)在 Windows 中成功编译,但它没有按预期工作,它只是抛出一个错误并杀死程序。我怎样才能使它在Windows上工作,请帮助。这是代码:
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <assert.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
int i, size, k = 2, ftab, sect = 3;
char buf[512];
char vbuf;
int dev, fil_descr, off=0;
fil_descr = open(argv[2], O_RDONLY);
assert(fil_descr > 0);
read(fil_descr, buf, 512);
close(fil_descr);
printf("Bootsector file: %s\n" ,argv[2]);
dev=open(argv[1], O_RDWR);
assert(dev > 0);
write(dev, buf, 512);
ftab = open("filetable", O_CREAT|O_RDWR);
sprintf(buf, "{");
write(ftab, buf, 1);
for(i = 3; i < argc; i++)
{
off = off + (k * 512);
lseek(dev, off, SEEK_SET);
fil_descr=open(argv[i], O_RDONLY);
assert(fil_descr > 0);
size = 0;
while((read(fil_descr, &vbuf, 1))!=0)
{
size++;
write(dev, &vbuf, 1);
}
k = (size > 512)?2:1;
sprintf(buf, "%s-%d," ,argv[i], sect);
write(ftab, buf, strlen(buf));
printf("Input file \'%s\' written at offset %d\n", argv[i], off);
close(fil_descr);
sect = sect + k;
}
sprintf(buf,"}");
write(ftab, buf, 1);
lseek(ftab, 0, SEEK_SET);
read(ftab, buf, 512);
lseek(dev, 512, SEEK_SET);
write(dev, buf, 512);
close (dev);
close(ftab);
}
【问题讨论】:
-
but it won't work , it just eject error and program close.但是哪个错误? -
"它只是弹出错误" 这是什么意思?您收到错误消息吗?为什么这个错误信息的内容是保密的?
-
“一个问题导致程序停止正常工作。Windows 将关闭该程序并在有解决方案时通知您”
-
您是否使用预期的参数运行您的程序?你有一些断言......
-
如何运行应用程序?请完整的命令行。