C语言程序问题,在VC++6.0中运行为什么总显示错误,如何改正
#include<string.h>#include<stdio.h>#include<errno.h>#include<dos.h>#include<io.h>intm...
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <dos.h>
#include <io.h>
int main(void)
{
int handle;
char buf[11] = "0123456789";
/* attempt to create a file that doesn't already exist */
handle = creatnew("DUMMY.FIL", 0);
if (handle == -1)
printf("DUMMY.FIL already exists.\n");
else
{
printf("DUMMY.FIL successfully created.\n");
write(handle, buf, strlen(buf));
close(handle);
}
return 0;
} 展开
#include <stdio.h>
#include <errno.h>
#include <dos.h>
#include <io.h>
int main(void)
{
int handle;
char buf[11] = "0123456789";
/* attempt to create a file that doesn't already exist */
handle = creatnew("DUMMY.FIL", 0);
if (handle == -1)
printf("DUMMY.FIL already exists.\n");
else
{
printf("DUMMY.FIL successfully created.\n");
write(handle, buf, strlen(buf));
close(handle);
}
return 0;
} 展开
1个回答
展开全部
char buf[12] = "0123456789"; //因为你后面操作是按字符串操作:strlen()。因此,这里在定义时,数组长度应该至少比数据长度大1,给\0留个位置。strlen(buf)函数是按\0位置返回字符串长度的!
更多追问追答
追问
用VC++6.0运行,一直是这个错误,为什么呢
error C2065: 'creatnew' : undeclared identifier
追答
标准C中没有creatnew()这个函数,需要你自己去实现!
你不会是抄来的代码吧,没有抄全?!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询