Hello everyone,

This will be my 1st post on this web-site so please excuse my ignorance in forum etiquette, if I am saying or doing something
wrong please educate/advise me & I will make the necessary corrections, thanks in advance.

My Back Ground Info:

Firstly My PC is an intel i7 Vpro HP Compaq Elite 8300 Small Form Factor PC with 8gb of ram fitted with DVD writer Is fitted with 2No HDD's with grub4dos dual boot setup with Windows XPSP3 (X86) & Q4OS (Linux) [nuthin special in terms of modern PC standards, & I just Luv WinXP so have stuck with it]

Competence level in Coding in C = Noob or Beginner (Had some basic grasp of batch file asm-debug coding) but not a lot more.

What I have installed on my XP-PC so far is Code Blocks ( It was a pig to setup due to XP being discontinued hacks were used in its installation) & because I couldn't get Code blocks to recognize MingW 32bit, so then I installed, after a further recommendation DEV-CPP V4.9.9.2 as it is allegedly better suited or easier for beginners to navigate and understand in terms of usage? I tried Visual studio 2010 Express but couldn't get it to function properly on my rig, too old.

Motives - I would like to learn how to write small C programs initially to compliment batch file programs from the DOS/CMD command-line. All low level at least to start with as I have to admit I am not the sharpest tool in the box when it comes to complex code writing but we all have to start some where right?

From the start off & before I show the code I have obtained, I just want to say that I did Not write this code example it was written by Iharob Al Asimi @ (All credits for this code belong to him & all kudos to him for sharing it!)

c - How to assign text file data to variable - Stack Overflow
Who very kindly donated this code to a fellow C program user & to others viewing the post. The title of the topic is "How to assign text file data to variable".

What I have done so far was to copy the C-code into notepad then copied the script into Code Blocks, I checked through the code, found a typo etc then went on-line because code blocks couldn't compile the script & ran it through the on-line C code compiler. The results were that I managed to get the majority of the code to work except for this one instance & is as follows:

Code:
Error(s):

1144516153/source.c: In function ‘main’:
1144516153/source.c:51:31: error: ‘inputFilename’ undeclared (first use in this function)
     content = readFileContent(inputFilename);
                                            ^~~~~~~~~~~~~
1144516153/source.c:51:31: note: each undeclared identifier is reported only once for each function it appears in
The program would be very useful to me in the respect that it back fills a hole in batch scripting referred to as command-substitution `Back-ticks in that a text file can be translated into a variable without jumping through a series of hoops to achieve the same result. Be careful though there may be some further typo's & the error line as above is indicated in bold type.

The script is as follows:

Code:
#include <stdio.h>
#include <stdlib.h>

char *readFileContent(const char *const filename)
{
    size_t size;
    FILE  *file;
    char  *data;

    file = fopen(filename, "r");
    if (file == NULL)
    {
        perror("fopen()\n");
        return NULL;
    }

    /* get the file size by seeking to the end and getting the position */
    fseek(file, 0L, SEEK_END);
    size = ftell(file);
    /* reset the file position to the begining. */
    rewind(file);

    /* allocate space to hold the file content */
    data = malloc(1 + size);
    if (data == NULL)
    {
        perror("malloc()\n");
        fclose(file);
        return NULL;
    }
    /* nul terminate the content to make it a valid string */
    data[size] = '\0';
    /* attempt to read all the data */
    if (fread(data, 1, size, file) != size)
    {
        perror("fread()\n");

        free(data);
        fclose(file);

        return NULL;
    }
    fclose(file);
    return data;
}

int main()
{
    char *content;

    content = readFileContent(inputFilename);
    if (content != NULL)
    {
        printf("%s\n", content);
        free(content);
    }
    reutrn 0;
}
Can someone with the relevant skills first explain what the error message is stating in layman's terms & secondly how I would repair this script to enable it to function properly as was intended & thirdly any tips that someone can give in respect of compiling the code. At first I wanted to compile it into a COM file as the structure is easier than an EXE but after further research it seems that I would have to compile it to an EXE first then change into a COM file which seems self defeating to me a bit so EXE may be my only choice here. I am hoping that the resultant EXE will work on XP CMD & Win98SE Dos Prompt but maybe my expectations and imagination may be unpractical in this venture?

Best Regards,

C-Gizzy