[Solved] Want to ask the user what file they want to scan in C [closed]


#include <stdio.h> 
#include <stdlib.h> 
// You need to include the relevant headers
//  - stdio.h  for printf, scanf etc
//  - stdlib.h for system

int main(void)
{
    char name[20];
    printf("Enter the file name: ");
    scanf("%19s", name);
    // Scan a string (word). Since the array size is 20, scan a 
    // maximum of 19 characters (+1 for the \0 at the end)
    // so that we don't run into a buffer overflow situation

    FILE* info;
    // Not recommended to use capital letters at the start for variables
    info = fopen(name, "r");
    if(info == NULL)
    {
        // Opening the file failed
        printf("Opening %s failed", name);
    }
    else
    {
        // Opening the file was successful

        // Read the file etc

        // Close the opened FILE object
        fclose(info);
    }

    system("pause");
}

5

solved Want to ask the user what file they want to scan in C [closed]