1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How do you open a file from user input?

Discussion in 'C' started by DaNxTh3xMaNx, Aug 31, 2010.

  1. DaNxTh3xMaNx

    DaNxTh3xMaNx New Member

    Joined:
    Aug 31, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I need to open a file that will be entered by the user and I don't know how to do this. I tried putting

    Code:
    ifp= fopen("%s", "r", &filename);

    //also tried:

    ifp= fopen(filename, "r");

    Code:
    printf("Enter the name of the file with the ticket data.\n");
    scanf("%s", filename);

    FILE *ifp;


    so what is the command you use to open a file based on user input that was stored in a variable filename?
     

Share This Page