#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main(){
        FILE *fp;
        fp=fopen("test","r");
        if(fp=NULL){
                printf("Error in opening file\n");
                exit(0);
        }
        else{
                char str[15],arr[200],temp,*add;
                add=arr;
                int i;
                while(!feof(fp)){
                        fscanf(fp,"%s",str);
                        for(i=0;i<(strlen(str)/2)+1;i++){
                                temp=str[i];
                                str[i]=str[strlen(str)-(i+1)];
                                str[strlen(str)-(i+1)]=temp;
                        };
                        strcpy(add,str);
                        add+=(strlen(add)+1);
                        *(add-1)=' ';
                };
                *(arr+strlen(arr))='\0';
                printf("%s \n",arr);
        };
        fclose(fp);
}
This code is written to read text from a file named test that contains only words and spaces and multiple lines.Whenever I try to execute it shows segmentation fault.
 
     
    