I had made a program in c in Ubuntu using gcc-7.I had sambleb.out file which is executable.I want to copy that file using c programming. here is the program.
#include <stdio.h>
int main()
{
    FILE *fp;
    fp = fopen("sampleb.out","rb");
    FILE *fpcp;
    fpcp = fopen("cp-of-sampleb.out","wb");
    char forcp;
    while (1)
    {
        forcp = fgetc(fp);
        if(forcp == EOF)
            break;
        fputc(forcp, fpcp);
    }
    fclose(fp);
    fclose(fpcp);
}
when I compile the program and execute the it, I get segmentation fault.
 $ a.out && chmod a+x cp-of-sampleb.out
 $ ./cp-of-sampleb.out
 Segmentation fault
here is the content of cp-of-sample.out
$ cat cp-of-sampleb.out 
ELF>0@@@@8  @@@@@@��88@8@@@,, `` ( 
((`(`��TT@T@DDP�td@@44Q�tdR�td``��/lib64/ld-
linux-x86-64.so.2GNU GNUX�T3�O���t�R�b�Ss�F
                                                  $ 
libc.so.6printf__libc_start_main__gmon_start__GLIBC_2.2.5ui 
3�`` `H�H�%
             H��t�CH��
and content of sampleb.out
$ cat sampleb.out 
ELF>0@@@@8  @@@@@@��88@8@@@,, `` ( 
((`(`��TT@T@DDP�td@@44Q�tdR�td``��/lib64/ld-
linux-x86-64.so.2GNU GNUX�T3�O���t�R�b�Ss�F
                                                  $ 
libc.so.6printf__libc_start_main__gmon_start__GLIBC_2.2.5ui 
3�`` `H�H�%
             H��t�CH���5
                          �%
                             @�%
                                 h������%
h������%�
]�8`��D]�fD�8`UH��8`H��H��H��H��?
H�H��t�H��tU�8`H=8`H��t�H��t
                                                ]�8`��]�fD�=a
uUH���~����O
]�D��@f.�UH��]��UH�忸@�������]�f.�DAWAVA��AUATL�% UH�- 
SI��I��L)�H�H���g���H��t 
1��L��L��D��A��H��H9�u�H�[]A\A]A^A_Ðf.���H�H��how are you I am 
fine this singale line is printed by multiline 
printf;4�����0���P����0��������zRx
�����*zRx
�$h���0FJ
U                                                                                         
�?;*3$"DW���A�C
Dd`���eB�B�E �B(�H0�H8�M@r8A0A(B BB�����@�@
�@` `���o�@@�@                                   �@
?
 `0�@�  ���o`@���o���oX@(`@@GCC: (Ubuntu 7.1.0-
5ubuntu2~16.04) 7.1.08@T@t@�@�@@X@`@    �@
�@
   �@
@0@�@�@@8@` `(`�``(`8`��
                                                       `@�@!
�@78`F `m@y`������(@���(`(���`�(`(8`8�08)8h�    P�
(I hadn't posted last line cause they were to many).Thus I can see that my program is coping only first 7 lines.It will be very helpful if you tell me what is wrong??? I am still noob.