opening and reading a file in c

 #include <stdio.h>


int main()
{
    FILE *ptr;
    int num1, num2;
    ptr = fopen("C:\\LearnC\\sample.txt", "r");

    fscanf(ptr, "%d", &num1);
    fscanf(ptr, "%d", &num2);
    if (ptr == NULL)
    {
        printf("The file does not exist");
    }
    printf("The value of num is %d\n", num1);
    printf("The value of num is %d\n", num2);
    fclose(ptr);
    return 0;
}

Comments