2012-04-06 6 views
0

機能gotoxy低レベルファイルコピープログラムに含まれていると、エラーが発生します。低レベルファイルコピープログラムでgotoxy()を使用中にコードを生成中にエラーが発生しました

ここでコード

#include<stdio.h> 
#include"d:\types.h" 
#include"d:\stat.h" 
#include"d:\fcntl.h" 
#include<windows.h> 

void gotoxy(int x, int y) 
{ 
COORD coord; 
coord.X = x; 
coord.Y = y; 
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); 
} 

main() 
{ 
int inhandle,outhandle,bytes; 
char buffer[512],source[128],target[128]; 
printf("enter source file location\n"); 
scanf("%s",source); 
printf("enter target file name with location\n"); 
scanf("%s",target); 
inhandle=(source,O_BINARY,O_RDONLY); 
if(inhandle==-1) 
{ 
printf("cannot open source file\n"); 
} 
outhandle=(target,O_CREAT,O_BINARY|O_WRONLY,S_IWRITE); 
if(outhandle==-1) 
{ 
printf("cannot create target file"); 
} 
while(1) 
{ 
bytes=read(inhandle,buffer,512); 
if(bytes>1) 
{ 
write(outhandle,buffer,bytes); 
} 
} 
close(inhandle); 
close(outhandle); 
} 

だと、ここで私が間違って何をやっているC-無料ver5.0コンパイラによって生成されたエラーのリスト

--------------------Configuration: mingw5 - CUI Debug, Builder Type: MinGW-------------------- 

Compiling D:\c\test4.c... 
[Error] C:\PROGRA~2\C-FREE~1\mingw\include\stdlib.h:293: error: conflicting types for '_fmode' 
[Error] d:\fcntl.h:107: error: previous declaration of '_fmode' was here 
[Error] C:\PROGRA~2\C-FREE~1\mingw\include\stdlib.h:293: error: conflicting types for '_fmode' 
[Error] d:\fcntl.h:107: error: previous declaration of '_fmode' was here 
[Warning] D:\c\test4.c:43:2: warning: no newline at end of file 

Complete Compile D:\c\test4.c: 4 error(s), 1 warning(s) 

ですか?どのようにしてコードを正常にコンパイルできますか?

+0

これらのエラーメッセージでは、あなたのgotoxy関数については言及していません。システム外のヘッダーにパスが含まれているのはなぜですか? – Mat

答えて

1

fcntl.hのコピーは、d:\(wtf?)で残りのシステムヘッダーと一致しません。そのようなシステムヘッダーを混在させたり、一致させたりしないでください。

さらに:gotoxy()はlib(n)curses関数です。 Windowsでは一般的に利用できません。必要に応じてPDCursesを調べることをおすすめします。

0

ヘッダが

#include <stdio.h> 
#include <sys/types.h> 
#include <sys/stat.h> 
#include <sys/fcntl.h> 
#include <unistd.h> 
#include <windows.h> 

それを動作させるために周りにそれらをコピーしないでくださいする必要があります。

エラーが発生した場合は、次のように処理してください。

inhandle=open(source,O_BINARY,O_RDONLY); 
if(inhandle==-1) { perror("cannot open source file\n");return -1;} 
outhandle=open(target,O_CREAT|O_BINARY|O_WRONLY,S_IRWXU); 
if(outhandle==-1) { perror("cannot create target file"); return -1;} 

whileループには終了点がありません。

while(bytes=read(inhandle,buffer,512),bytes>1) { 
if (write(outhandle,buffer,bytes) == -1) { perror("write");break; } 
} 

プログラムが以前に働くことができなかった、それを壊したgotoxyの包含ではなかった。

関連する問題