-4
私は質問がありますが、ポインタからファイルへの行をコピーしようとしましたが、ポインタとポインタを比較できないというエラーが1つあります。エラーがラインch = getc(file1);
にあり、int
へchar *
からch
のwhile(ch != EOF)
ポインタと整数の比較
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#define GetCurrentDir getcwd //get the path of file
#define BUFFER_LEN 1024
int main(){
char cCurrentPath[FILENAME_MAX]; //get
char line[BUFFER_LEN]; //get command line
char* argv[100]; //user command
char* path= "/bin/"; //set path at bin
char *ch;
char progpath[20]; //full file path
int argc; //arg count
FILE *file1, *file2; //Files for history
int delete_line, count=0; //line to delete and counter
while(1){
file1 = fopen("fileOne","w");
if(GetCurrentDir(cCurrentPath, sizeof(cCurrentPath)))
{
printf("%s",cCurrentPath);
}
printf("/SimpleShell>> "); //print shell prompt
if(!fgets(line, BUFFER_LEN, stdin))
{ //get command and put it in line
break; //if user hits CTRL+D break
}
else if(line, BUFFER_LEN, SIGQUIT){
fopen("fileOne.c","r");
ch = getc(file1);
while(ch != EOF){
printf("%s",ch);
}
}
if(count<20)
{
fputs(argv[100] ,file1);
}
else{
fclose(file1);
file1 = fopen("fileOne.c","r");
rewind(file1);
file2 = fopen("repicla.c","w");
ch = getc(file1);
while(ch != EOF){
ch = getc(file1);
if(ch != "\n"){
count++;
if(count != 20){
putc(ch, file2);
}
}
}
fclose(file1);
fclose(file2);
remove("fileOne.c");
rename("replica.c","fileOne.c");
fputs(argv[100] ,file1);
}
'getc'などに変更すると、意図的に' char'ではなく 'int'が返されます! 'while(ch!= EOF){' char ch;は非常に間違っています! 'fopen'などの関数の結果を確認してください! – Olaf
'char'を' char'の代わりに 'char *'として宣言しました –
@PatrickRoberts 'getc'の戻り値を' char'に格納することは情報を失うため、受け入れられません。 – melpomene