哭笑不得
这个问题太奇怪了,请各位试着运行我下面的代码,工作很简单,就是读一个文件,然后用system call来以特定的方式写进另一个新建的文件里,linux下运行
#include "unistd.h"
#include "fcntl.h"
#include <sys/types.h>
#include <cstdlib>
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
int main()
{
//step 1:
int f1,o1,r,w,rf1,rf2,fp,o2, o3, fx, w_xxx, w_www, del, total, l;
char buffer[100], print1[150], print2[150];
o1 = creat("XYZ.doc",0755); //create own file
f1 = open("xx.xx",0); //open file
while (r>0)
{
r = read(f1,&buffer,100); //read file
if (r <0) //if read operation failed...
{
cout<<"A read error has occurred!"<<endl;
exit(0);
}
w = write(o1, &buffer, 100); //write data into own file from xx.xx
char string[] = "X1Y2A3";
w = write(o1, &string, 6);
if(w<0) //if write operation failed...
{
cout<<"A write error has occurred!"<<endl;
exit(0);
}
lseek(f1, 0, 1); //locate to next character
}
close(o1); //close own file
fp = open("XYZ.doc", 0); //open file
lseek(f1,0,0); //locate to the beginning of file
memset(print1,'\0',sizeof(print1)); //intialize array for printing
memset(print2,'\0',sizeof(print2));
rf1 = read(f1, &print1, 120); //read data for printing
rf2 = read(fp, &print2, 120);
printf("%s\n",print1); //print
printf("%s\n",print2);
//cout<<print2<<endl;
close(fp);
close(f1); //close file xx.xx
return 0;
}
注意红字部分,程序应该是没有问题的,现在我们随便在红色部分变量声明的地方加一个变量,比如加个xx,使红字部份变为int f1,o1,r,w,rf1,rf2,fp,o2, o3, fx, w_xxx, w_www, del, total, l, xx;
请再运行看看,变量名可以随便取,反正只要你加个变量,不论是否用到,这个程序就出错了。。。
帮忙想想办法。。。
#include "unistd.h"
#include "fcntl.h"
#include <sys/types.h>
#include <cstdlib>
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
int main()
{
//step 1:
int f1,o1,r,w,rf1,rf2,fp,o2, o3, fx, w_xxx, w_www, del, total, l;
char buffer[100], print1[150], print2[150];
o1 = creat("XYZ.doc",0755); //create own file
f1 = open("xx.xx",0); //open file
while (r>0)
{
r = read(f1,&buffer,100); //read file
if (r <0) //if read operation failed...
{
cout<<"A read error has occurred!"<<endl;
exit(0);
}
w = write(o1, &buffer, 100); //write data into own file from xx.xx
char string[] = "X1Y2A3";
w = write(o1, &string, 6);
if(w<0) //if write operation failed...
{
cout<<"A write error has occurred!"<<endl;
exit(0);
}
lseek(f1, 0, 1); //locate to next character
}
close(o1); //close own file
fp = open("XYZ.doc", 0); //open file
lseek(f1,0,0); //locate to the beginning of file
memset(print1,'\0',sizeof(print1)); //intialize array for printing
memset(print2,'\0',sizeof(print2));
rf1 = read(f1, &print1, 120); //read data for printing
rf2 = read(fp, &print2, 120);
printf("%s\n",print1); //print
printf("%s\n",print2);
//cout<<print2<<endl;
close(fp);
close(f1); //close file xx.xx
return 0;
}
注意红字部分,程序应该是没有问题的,现在我们随便在红色部分变量声明的地方加一个变量,比如加个xx,使红字部份变为int f1,o1,r,w,rf1,rf2,fp,o2, o3, fx, w_xxx, w_www, del, total, l, xx;
请再运行看看,变量名可以随便取,反正只要你加个变量,不论是否用到,这个程序就出错了。。。
帮忙想想办法。。。
...全文
相关推荐
初中语文文摘社会哭笑不得的中国制造
初中语文文摘社会哭笑不得的中国制造
脑筋急转弯-什么东西使人哭笑不得.doc
脑筋急转弯-什么东西使人哭笑不得.doc
那年曾让我哭笑不得抓狂的C语言
int类型在大多数16位CPU构架中占用两个字节,但在32位CPU中却往往占用4个字节;char类型在绝大多数编译器中都是有符号数,但在keil MDK中却是无符号数,若是要在keil MDK下定义有符号char类型变量,必须用signed显式声明。
happy pig <快乐小猪>
资源大小 2KB 作弄朋友用此最好不过!发过他,会让他哭笑不得!
愚人节和清明节联合整蛊代码
愚人节和清明节联合整蛊的页面就是可以给好朋友建立一个墓园,然后让大家都来给他扫墓,搞得他哭笑不得,采用ASP+Access开发,4个页面,希望喜欢,代码粗糙,见笑了。时间仓促,没有后台,不做支持。1、如果放在根目录测试,注意改conn里的地址。2、应编辑要求去掉谷歌广告,用的时候自己添上


