segmentation fault (core dumped) comes when i compile the below code:
Code:#include<stdio.h> void main(void){ FILE *fp1,*fp2; fp1=fopen("file1","r"); fp2=fopen("file2","w"); char ch; while((ch=fgetc(fp1))!=EOF){ fputc(ch,fp2); } }
segmentation fault (core dumped) comes when i compile the below code:
Code:#include<stdio.h> void main(void){ FILE *fp1,*fp2; fp1=fopen("file1","r"); fp2=fopen("file2","w"); char ch; while((ch=fgetc(fp1))!=EOF){ fputc(ch,fp2); } }
Thank you, it works now (Y)
To add, you always need to check the return value from any of the buffered I/O functions, especially the open, read, and write functions. That would have shown up the missing file when trying to open a non-existent file.
Also, fgetc() returns an int, so your variable "ch" should be an int too.