FILE *PF;
FILE *BukaFile(char *NF,char Mode[]);
main()
{
char NamaFile[40],C,Jawab;
system("cls");
printf("Nama File ? ");
scanf("%s",NamaFile);
printf("\n");
if(BukaFile(NamaFile,"r")==NULL){
printf("File Belum Ada, Buat Baru (Y/T)? ");
Jawab=getche();
printf("\n");
if(!(Jawab=='Y'||Jawab=='y'));exit(0);
}
else{
printf("Isi File Sebelumnya:\n");
while((C=getc(PF))!= EOF)putchar(C);
printf("\n");
}
fclose(PF);
if(BukaFile(NamaFile,"a")==NULL){
printf("KESALAHAN:Tidak Dapat Memebuka File Baru !!!\n");
exit(1);
}
printf("Masukkan Data Karakter-karakter Baru (Enter untuk selesai):\n");
while((C=getche())!= '\r')
putc(C,PF);
fclose(PF);
}
FILE *BukaFile(char *NF,char Mode[])
{
return(PF=open(NF,Mode)); //Warning
}
When I compile and run the code I get this warning:
||In function 'BukaFile':|
|43|warning: assignment makes pointer from integer without a cast [enabled by default]|
||=== Build finished: 0 error(s), 1 warning(s) (0 minute(s), 1 second(s)) ===|
results if true :
Nama File ? example.txt
File Belum Ada, Buat Baru (Y/T) ? Y
==This Text== (Enter for finish)
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
Dear Asrianor
lines 1,2,3,4 should be
include <stdio.h>
include <stdlib.h>
include <conio.h>
include <string.h>
the function Buka file goes like this
FILE* BukaFile(char *NF,char Mode[])
{
return(PF=fopen(NF,Mode));
}
it is fopen() and not open()
and use getchar in place of getche.
for your convienience I place before you compiled and executed program using the following
OS Ubuntu 16.04
PROGRAM Geany
and the listing of the program is
include <stdio.h>
include <stdlib.h>
//# include <conio.h> is not used in Ubuntu
include <string.h>
FILE *PF;
FILE *BukaFile(char *NF,char Mode[]);
int main()
{
char NamaFile[40],C,Jawab;
}
FILE* BukaFile(char *NF,char Mode[])
{
return(PF=fopen(NF,Mode));
}
The program compiles and executes without problem