i'm a beginner in this world (c++) and i need to open a file (i know that the function to be used is fopen) but i need the program asks for the text to be loaded. I got this.
#include<stdio.h>
int main(){
FILE* fptr;
char filename[10];
printf ("Please type the name of the file to be loaded:");
scanf("%c",filename);
if((fptr=fopen("filename","r"))==NULL){
printf("Cannot open the file\n");
}else{
printf("File opened successfully for reading\n");
}
fclose(fptr);
return 0;
}
But unfortunately it doesn't work. what can i do??? I would thank to someone help me with this little problem. Also i got a segmentation fault problem..What is that????