Hi im new and i was wondering if anyone could help me with this code
i keep getting warnings and if this helps too i edit it in visual c++ and compile with borlands c/c++ compiler because visual c++ compiler doesnt work for meCode:/* ******************************* * author:kevin peters * revison #:0.1 **********************************/ #include <stdio.h> #include <stdlib.h> #define QUIT 5 char filename[80]; int get_menu( void ); FILE *fp; main() { int choice = 0; /* while() makes sure choice does not equal QUIT */ while (choice != QUIT) { choice = get_menu(); if (choice == 1) { // creates file puts("Enter a name for the file:"); gets(filename); if ((fp = fopen(filename, "w")) == NULL) { fprintf(stderr, "Error creating file %s", filename); exit(1); } fclose(fp); } if (choice == 2) { //edits previous file puts("Enter a file to edit:"); gets(filename); if ((fp = fopen(filename, "w")) == NULL) { fprintf(stderr, "Error opening file."); exit(1); } fclose(fp); } if (choice == 3) { //reads a file puts("Enter a file to read:"); gets(filename); if ((fp = fopen(filename, "r")) == NULL) { fprintf(stderr, "No exsiting file."); exit(1); } fclose(fp); } if (choice == 4) { // deletes previous file puts("Enter a filename to remove: "); gets(filename); if ( remove(filename) == 0) printf("Succesful deletion of %s", filename); else fprintf(stderr, "Error deleting file %s", filename); exit(1); } } return (0); } int get_menu( void ) { int selection = 0; /* display menu() to screen */ do { printf("\n"); printf("1 - Create entry\n"); printf("2 - Edit previous entry\n"); printf("3 - Read previous entry\n"); printf("4 - Delete previous entry\n"); printf("5 - Quit\n"); printf("\n"); printf("\nEnter what you would like to do: "); scanf("%d", &selection); } while (selection < 1 || selection > 5); return selection; }



LinkBack URL
About LinkBacks


