Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

How to prompt user to enter filename in c

$
0
0
I am trying to create a program that will ask the user for a file name and then read that file. This is the first part of an assignment that will teach us how to encrypt plain text files. Here is what i have so far:
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
char filename[20];
printf("Enter the file name");
scanf("%s",filename);
FILE *fileptr;
fileptr=fopen(filename,"r");
}


When i run this program, i am asked to enter the file name but after i do, it just closes.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>