I am calling a function that's supposed to ask the user to name the file he wishes to open. Then, this file is opened using the fopen() function. I am a little lost as how this works. Here's the code, which doesn't work as it crashes the program.
I only wanted to see if the option 1 worked and when I get it to work, I'll move to option 2. With option 1, it's supposed to do 3 things:Code:#include <stdio.h> #include <conio.h> #include <string.h> void create(FILE*); /*function prototype*/ int main() { int ch; FILE*editor; do { printf("\nPlease choose an option below by typing a number between 1 and 8.\n\n"); printf("1\tCreate text file\n\n"); printf("2\tCount Characters,words and sentences\n\n"); printf("3\tConvert to lowercase\n\n"); printf("4\tConvert to uppercase\n\n"); printf("5\tEncrypt text\n\n"); printf("6\tDecrypt text\n\n"); printf("7\tDisplay text file\n\n"); printf("8\tExit program\n\n"); scanf("%d", &ch); switch(ch) { case 1: create(editor); case 2: printf("\nJust is just a test"); } }while(ch!=0); return 0; } void create(FILE*fname) { //FILE*fname; char fileName[13]; printf("\nPlease enter the file you wish to open: "); gets(fileName); fname=fopen(fileName,"w"); if (fname==NULL) { printf("\nThe file cannot be opened."); printf("\nPlease check that the file exists."); //exit(1); } return; }
1.) Request the name of the file
2.) Request the text.
3.) Write the text to the file.
Then, after completing n option, except for #8, supposed to return the menu to the screen. The main() will consist mainly of function calls. Thanks for any help! Tommy