Thread: Assistance with C Code correction Please?

  1. #1
    Registered User
    Join Date
    Feb 2021
    Posts
    7

    Assistance with C Code correction Please?

    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

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    > 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?
    Not really, it's just that DEV-CPP V4.9.9.2 was abandoned at pretty much the same time that M$ abandoned XP.
    So they're kinda matched for one another by default.

    But beware that dev-cpp likes to trash it's own project files, so it's only really useful for single file toy programs.

    > content = readFileContent(inputFilename);
    You need to take it a bit less literally.

    Like
    Code:
    char inputFilename[100];
    printf("Enter a filename > ");
    scanf("%s",inputFilename);
    content = readFileContent(inputFilename);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Feb 2021
    Posts
    7
    Hi Salem,
    Firstly many thanks for responding to my post it is most appreciated, so if I am reading you correctly for medium to long term use dev-cpp is kinda ring fenced to XP & is only really suitable for say small programs below say < 64Kb. So I need to to concentrate more so on code-blocks & get that running with Mingw. Code Blocks is fine apart from the Mingw aspect not working which is blocking me from compiling up to now. I see I will need to persevere.
    > "You need to take it a bit less literally." Could I request further elaboration in what you are stating here Please? My assumption is I need to interchange your code into the original code like so:? Is there any chance you could comment each line of your proposed code please?

    Code:
    int main()
    {
             char inputFilename[100];
             printf("Enter a filename > ");
             scanf("%s",inputFilename);
             content = readFileContent(inputFilename);
             if (content != NULL)
        {
             printf("%s\n", content);
             free(content);
        }
             Return 0;
    }
    The way I am hoping this program operates is for example the user would provide a given character or numerical string text file, lets for e.g. call it var.txt & you would redirect var.txt into the compiled program like for instance (lets call the resultant compiled program txt2var.exe) like so
    Code:
    path\txt2var.exe<var.txt
    & the output from the var.txt would be a variable based on the contents of the var.txt file. Is printf("Enter a filename > "); line
    requesting user input? Apologies for all the questions but trying to get my head around it?
    Best Regards,
    C-Gizzy

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    > so if I am reading you correctly for medium to long term use dev-cpp is kinda ring fenced to XP & is only really suitable for say small programs below say < 64Kb.
    No, the IDE part is crap.
    You can use the underlying GCC compiler (albeit one that's massively out of date) from a command line just fine.
    It might be better for you actually, given your low level approach.
    You just need a decent text editor like notepad++

    If you want to use redirection, then there is no file to open.
    But then you also lose the ability to do meaningful fseek, ftell and rewind.

    So a different approach to readFileContent is needed.
    One that would work with all kinds of files.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Feb 2021
    Posts
    7
    Hi Salem

    Again many thanks for getting back to me on this venture you are a credit to this forum for giving me advice like this. Thanks for the warning info re the Dev-cpp IDE & Notepad++ these are good things to know and apply.

    >If you want to use redirection, then there is no file to open.
    But then you also lose the ability to do meaningful fseek, ftell and rewind.

    >So a different approach to readFileContent is needed.
    One that would work with all kinds of files.

    I see, so in this particular instance I would need some form of internal error level check to establish the file to be read is in the first place a text-file in composition & not for e.g. a binary-file, then "IF" the file is Text based, read the contents and convert the contents to a variable? Otherwise it could get complicated in that I would need to incorporate a flag option on/off (e.g. -x) built in to cater for both options which would increase the complexity of the program dramatically?

    Some possible scenario's or one way of looking at it:
    The redirection method offers the benefit of batch-file creation of the variable for example say I wanted to setup a variable for text string that was say my current path the user could simply setup the text file hypothetically like so
    Code:
    CD>CURPATH.TXT
    This would setup a text file for example "C:\windows\system32" then using Txt2Var.exe
    Code:
    Txt2Var.exe<CURPATH.TXT
    Define the variable to the path C:\Windows\system32
    Of course the user could simply just type a text with lets say for instance "Hello World" save it as a text file then use Txt2Var.exe again & define Hello world as a Variable.

    I may have also spotted a further problem or glitch on top of the error level check which I have not considered, (There is in fact two identified operations that Txt2Var.exe need to be undertaken here)
    This operation would setup a variable directly whereas generally in batch you would give the variable a label-name e.g.
    SET MYVAR=WHATEVER ----> MYVAR would be the indicator of the variable so it would need to be connected in some way to variable generated by Txt2Var.exe program otherwise the variable would not be able to be used or called. For example here's my half baked illustration of the two operations illustrated

    Operation 1)
    Txt2Var.exe would need to be able firstly be capable of receiving SET VARIABLENAME= instruction from either user input or a text file pre-setup to indicate the variable name/label like SET MYVAR= .(probably the easiest option would be input from a pre-setup text file not user input directly the user input would add further complication & probably upon reflection just as easy as typing the info in directly). In effect let the text file do the communication, not the user input method thus utilizing the acronym KISS keep it simple....
    Stage 1 - Operation1.txt> Txt2Var.exe

    Then

    Operation 2)
    Txt2Var would then need to be capable of taking input from a second text file containing the variable text information to be setup. Again the user input option
    could be skipped in favor of the pre-setup text-file. Functionally a bit like this using redirection out & into Txt2Var

    Code:
    Stage 2 - Operation1.txt> Txt2Var.exe <Operation2.txt
    Redirect operation1.txt into ---> Txt2Var.exe <----- and then input Operation2.txt
    Thus as in the example above would become
    Code:
    SET MYVAR=C:\windows\system32
    -----> Then MYVAR could be called by
    Code:
    Echo Your CurPath is %MYVAR%
    Again the error level would need to distinguish between Binary & Text-files like you have stated otherwise a crash failure would result unless I used a file extension like for example an extension that is confined only to Txt2Var it would only be able to use Text-files lets say ".VAR" predefined file extension that Txt2Var would use otherwise would then stall.
    For e.g.
    Code:
    SETTXT.VAR > Txt2VAR.exe < VARINFOTOBESET.VAR
    I think Txt2Var would primarily be more batch-file orientated util rather than command-line util. Once I became a bit more competent at writing C code could develop further improved features, but first learn to walk before trying to run? So what in your opinion would be the best approach to readFileContent or otherwise, if the redirection approach was adopted from two source text files please? Am I right in assuming this is the required structured approach to this venture & would it necessarily result in a rewrite of the original C code? I will need to extend my apologies to you as can see I have not clearly thought this through properly, "opened a can of worms" so to speak

    Best Regards,

    C-Gizzy

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    > I see, so in this particular instance I would need some form of internal error level check to establish the file to be read
    > is in the first place a text-file in composition & not for e.g. a binary-file, then "IF" the file is Text based, read the contents and convert the contents to a variable?
    No that isn't what I meant, and no the type of file is immaterial to the problem to be solved.

    stdin cannot be seeked - pure and simple.
    If you redirect a binary file, you won't know anything until you start seeing bytes which aren't printable.

    What does work is this.
    Code:
    char buff[BUFSIZ];
    while ( fgets( buff, BUFSIZ, stdin ) ) {
      // do something with buff, like say
      // append it to your result string
      // but you may need to realloc the space to
      // grow the result as necessary
    }
    And if you fopen a file, it's the same code.
    Code:
    FILE *fp = fopen("myfile.txt","r");
    char buff[BUFSIZ];
    while ( fgets( buff, BUFSIZ, fp ) ) {
      // do something with buff, like say
      // append it to your result string
      // but you may need to realloc the space to
      // grow the result as necessary
    }
    stdin is a FILE*, so fgets is perfectly happy reading from a real stdin, a redirected stdin or an fopen'ed file.

    Also, there is no such thing as "a text file" or "a binary file". There's no magic bit on the file system to tell you which is which, and you simply can't trust the extension .txt to mean a text file.

    Try copy prog.exe prog.txt ; prog.exe < prog.txt and enjoy the light show.
    Sure, you can hope for the best and assume it's a text file in the usual sense, but you should prepare for the worst as well.

    > Txt2Var.exe would need to be able firstly be capable of receiving SET VARIABLENAME= instruction
    Yeah, this is never going to work either.
    Environment variables only propagate from parent to child. The child can mess with the environment as much as it wants, but that will never change a bean in the parent environment.

    The clunk-fest that is setting variables from the output of commands in win32 consoles.
    Reading the output of a command into a batch file variable | The Old New Thing

    Getting things done in cmd.exe
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Feb 2021
    Posts
    7
    Hi Salem,

    > Getting things done in cmd.exe
    Raymond Chen - Re batch file limitations a guru & yes a discussion involving the For command which is quite limited in Dos. For is really best suited to CMD/NT due to its limitations in Dos. I believe there was an individual who wrote a program called fortune for dos which expanded For's capabilities but I have never tried it though.
    LOL Ball & Chain Precisely, hence trying to back fill areas (& yes there are many) with complimentary programs to get the job done but yes point taken & conceded. Perhaps it's because I'm a masochist or like a challenge in heading down this road (oh whats this, it looks like an impending cul-de-sac in view). My hope was that a very small C program would bridge this gap to what the surface seemed relatively easy UMMmmm.

    Just brain storming here but what about rather than using redirection(>) what if, & I couldn't say if in C you would be able to achieve this but, what if both text files were individually read & stored into Txt2Var lets call them stage1.txt/.var & stage2.txt/.var.
    stage1.var could contain some predefined text like SET MYVAR= & stage2.var (& both restricted to a max of 78 chars) directly translated & stored into two variables %stage1% %stage2% then concatenate/add the two vars & set MYVAR=WHATEVERUPTO78. Is this a possible avenue that could be explored? I know you can concat vars in CMD & these wouldn't be parental?

    The only other way I can think of & I have never tried this though is to use the Windows/Dos clipboard & in the case of windows clipboard would need windows OS running to perform. This would be a limiting factor. I suppose in a sense it is trying to work within CMD/Dos limitations & structure combined with C in the hope that C can fill the gap in respect of CMD/Dos in the efficient practical manner. & on that point

    Code:
    >  // but you may need to realloc the space to
    >  // grow the result as necessary
    > }
    Could this be restricted to one line of text say 80no chars for a standard line length in CMD/DOS prompt however but possibly need to appreciate \n (EoL) & restrict to 78 Chars? This would stop the user entering copious amounts of text or lines of text thus eroding enviro space, just a thought (restrict to just one line)? The other consideration (not sure in "C" can you mix/read text with integers on the same line or within say the 78 or so Chars/int's or do you have to identify both separately or use another general type identifier for each? One further thought in the case of Zero byte text files where for instance say the outcome of the text-file generation, the file generated was empty or void of text would this need to be taken into account can C distinguish file size or lack of it? It seems looking at your earlier code snippet char inputFilename[100]; seems to have been limited to 100 chars possibly? e.g. test IF char inputFilename[0]or [""] then exit to mitigate this eventuality?

    Thanks for the additional optional code snippets & pointers I will need to read up and understand the structure/context etc to rebuild the Txt2Var file. It is really good communicating with individuals like yourself who know what they are doing, a bit like a lamp unto my path, illustrating the pitfalls it all helps the learning process etc. From ground zero, onward and upward as they say.

    Best Regards,

    C-Gizzy

  8. #8
    Registered User
    Join Date
    Feb 2021
    Posts
    7
    Hi Salem ,

    For others who may venture to this post hoping to find a solution to the question raised by yours truly. I have stumbled upon some code which will to a large degree (95%) do what I was hoping to achieve.
    The two caveats are:
    1) File1.txt needs to be created without any EoL (CRLF) instances why? because in my case I need to create the Variable all on one line (Concatenate the files) like so:
    Set MyVar=whatever text string you want (As long as not more than 78 chars which equates to a single line in CMD)
    2) Limiting text to a given numbers of chars
    The user would setup the 3 text files the third would be a bat/cmd to be called see respective contents below
    File1.txt (Ltd)| File2.txt (Ltd)
    ------------------------------------------------------------------
    SET MYVAR= | Whatever text you want (Ltd to say 65 chars)
    (Ltd to 13 chars)

    File3.bat would be setup to receive the text
    I'm hoping by leaving out the code highlighted in bold & in red below the EoL removal issue can be taken care of?
    Question - How would you limit file1.txt to 13 chars & say File2.txt to 65 chars and how would you scrub Eol from File1.txt?

    I have run the code and no errors are reported so I assume it is okay so the basic framework is there. I think I will change the hard-coded files to File1.var & File2.var.
    Not sure if there should be an error level message generated if File1.var and/or File2.var along with File3.bat/cmd (File called & used to setup the variable) are missing or File1.var & File2.var could be void of text strings & maybe some text printed to screen which states something to the effect, "this routine has completed successfully"? Anyway without further prattling here is the "C" Code.

    I have included details pertaining to the source of the information e.g. website name and link along with how the code was formulated.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
     
       // If you like this code you can grab a copy from link below from geeks4Geeks
       // https://www.geeksforgeeks.org/c-program-merge-contents-two-files-third-file/
       // Let the given two files be file1.txt and file2.txt. The following are steps to merge.
       // 1) Open file1.txt and file2.txt in read mode.
       // 2) Open file3.txt in write mode.
       // 3) Run a loop to one by one copy characters of file1.txt to file3.txt.
       // 4) Run a loop to one by one copy characters of file2.txt to file3.txt.
       // 5) Close all files.
       // Merged file1.txt and file2.txt into file3.txt
       // To successfully run the below program file1.txt and file2.txt must exists in same folder.
      
    int main()
    {
       // Open two files to be merged
       FILE *fp1 = fopen("file1.txt", "r");
       FILE *fp2 = fopen("file2.txt", "r");
      
       // Open file to store the result
       FILE *fp3 = fopen("file3.txt", "w");
       char c;
      
       if (fp1 == NULL || fp2 == NULL || fp3 == NULL)
       {
             puts("Could not open files");
             exit(0);
       }
      
       // Copy contents of first file to file3.txt
       while ((c = fgetc(fp1)) != EOF)
          fputc(c, fp3);
      
       // Copy contents of second file to file3.txt
       while ((c = fgetc(fp2)) != EOF)
          fputc(c, fp3);
      
       printf("Merged file1.txt and file2.txt into file3.txt");
      
       fclose(fp1);
       fclose(fp2);
       fclose(fp3);
       return 0;
    }
    Any further help or tips from anyone would be appreciated like the best way to ensure a compiled EXE file is compatible with Windows 98SE Dos & NT CMD. Many Thanks to Salem for all your help and assistance I am very grateful for your helpful advice!

    Njoy!

    C-Gizzy

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Well if you only want the first line excluding the \n, then do this
    Code:
       while ((c = fgetc(fp1)) != EOF && c != '\n')
          fputc(c, fp3);
    Then it doesn't matter what the input file has at the end.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  10. #10
    Registered User
    Join Date
    Feb 2021
    Posts
    7
    Hi Salem,
    Just quick note, my internet is up the creek at the moment, message sent from my phone which is not good. I will
    Indeed use your code it is necessary and gratefully received many thanks hope to get fix for internet
    Tomorrow. Apologies normal will resume shortly lol
    Best regards
    C

  11. #11
    Registered User
    Join Date
    Feb 2021
    Posts
    7
    Hi Salem
    Plusnet Internet up and running again!
    1) Yes, indeed I will certainly interchange your code as it keeps the stream of text to one line many thanks it is certainly pivotal role in the functional execution of Txt2Var. Without it, CRLF would have put the contents of the 2nd File2.bat on a second line & thus would fail to operate when File3bat is called.

    2) If Txt2Var gets to a point where a reasonably functional open source prototype would you object to me mentioning your name (in positive fashion) in dispatches (and if it did not breach any of this forums rules or etiquette I do not want to cause and controversy here)? I am also a member of DosTips forum (Albeit I have to add a very minor player though & also go under another handle name Ispy) as I think it would help Dos/CMD users in another hack option to get over command substitution limitation in Dos. I could cross link with web links from this site to dos tips and vice versa? What do you think, can you see any for see-able objections in doing this?

    3) I have further possible improvements for Txt2Var I would like to run by you if that is Okay? I have tweaked the "C" code a little bit more, in that I have altered the Txt files to bat files format (Which are still text in format so should be okay) I have removed some of the comments just to condense the code a bit. After File3.bat is made I have put a "call" statement to set the variable from File3.bat. Then I have attempted to put a delete operation to remove the 3no temporary .bat files once the call routine has completed. However I'm not sure about this protocol, are you allowed you use the "?" question mark to replace the numbers on the three bat files e.g. 1,2&3 with "File?.bat" I wasn't sure however when using the call & delete operations the 3no .bat files would need to be in a closed state hence closing the bat files first in "C"? & additionally the IF statement caters for if the bat files "Do not exist" however what about error checking if File1 & File2.bat are empty as per code below. I'm thinking about "if" the user generates, by mistake one or two empty bat files before the program initiates the program, it will fail? Anyway here is the tweaked code below I have narrowed the errors from 12no to just 2 but 2 errors remain: 1 = In function `main:' which maybe something to do with a missing # headers and the other is in line 11 which is a blank line so I assume is referring to line 10
    which is this line size = ftell(fp1); which is repeated on line 23 but that one isn't flagged as an error?

    Code:
    #include <stdio.h> 
    #include <stdlib.h>
    
    int main() 
       { 
       // Open two files to be merged 1st file1.bat
       // and check if file1 and File2.bats are empty
       FILE *fp1 = fopen("file1.bat", "r");
       if (NULL != fp1) {
           fseek(fp1, 0, SEEK_END);
           size = ftell(fp1);
    
           if (0 == size) {
               printf("This bat file is empty\n");
               printf("Exiting the program....\n");
           exit(0);           
           }
    }
       // I kinda suspect that something should go here for
       // continuation to link to file2.bat below???
           
       // open 2nd file2.bat and check if empty   
       FILE *fp2 = fopen("file2.bat", "r");
       if (NULL != fp2) {
           fseek(fp2, 0, SEEK_END);
           size = ftell(fp2);
    
           if (0 == size) {
               printf("This bat file is empty\n");
               printf("Exiting the program....\n");
           exit(0);
           }
    }          
         // Open file to store the result
         // This file is already empty so no check
        FILE *fp3 = fopen("file3.bat", "w");
        char c; 
      
       if (fp1 == NULL || fp2 == NULL || fp3 == NULL) 
       { 
             puts("Could not open these files"); 
             exit(0); 
    } 
         // Copy contents of first file to file3.bat 
       while ((c = fgetc(fp1)) != EOF && c != '\n')
          fputc(c, fp3); 
      
       // Copy contents of second file to file3.bat 
       while ((c = fgetc(fp2)) != EOF && c != '\n')
          fputc(c, fp3); 
      
       printf("Merged file1.bat and file2.bat into file3.bat"); 
      
       fclose(fp1); 
       fclose(fp2); 
       fclose(fp3);
    
       printf("Calling batch file file3.bat\n");
       system("file3.bat");
    
       int del = remove("File?.bat");
       if (!del)
          printf("The temporary bat files have been Deleted successfully");
       else
          printf("The temporary bat files have not been Deleted");
    
          return 0; 
    }
    Not sure about the placement of curly brackets & whether this would be the best way of writing "C" code?

    4) The another worry/concern I have is in respect of keeping the the single line in File2.bat & File3.bat as long as possible for say long paths. I assume "C" does not care how long the line of chars is as long as the EoL crlf's are omitted which I have done with the insertion of your code (thanks again). However A long file name (LFN) can be up to 255 characters long. NTFS supports paths up to 32768 characters in length, but only when using the Unicode APIs. Would it be prudent to limit the chars to 232 particularly in the case of "File2.bat" with error printf error message if longer file1.bat could be say 15?

    5) & pen-ultimately the only other check I can think of is in the case of checking to see if the variable is defined after the call statement like in batch
    IF "%myvar%"=="" echo myvar is NOT defined
    Is there a way in "C" to undertake this check or is it best left to the batch user to batch check it possibly once Txt2Var has terminated?

    6) & lastly on the geeks for geeks site that demonstrated this method of using 3 text files to set cat 3 text files, in the comments section one "C" user stated this (start):
    Gangani Roshan
    Above program content can't copy use or operation and by default file 3 content is null so my suggestion is replace or operation with and (end)
    Do you think he has a point & really the && or & operator should be used instead of If || (or) code?

    Never thought that so many considerations would need to be taken into account & this is just a small program you live and learn as they say.

    Best Regards,
    C-Gizzy
    Last edited by C-Gizzy; 03-03-2021 at 03:11 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code Assistance
    By rawr12 in forum C Programming
    Replies: 16
    Last Post: 03-22-2013, 02:00 PM
  2. help with hamming code error detection/correction
    By thebiff in forum C Programming
    Replies: 0
    Last Post: 10-20-2010, 01:36 PM
  3. Code Assistance
    By Nezmin2 in forum C Programming
    Replies: 12
    Last Post: 12-19-2008, 12:26 AM
  4. code for the correction..
    By mrprogrmr in forum C Programming
    Replies: 10
    Last Post: 12-16-2004, 03:09 AM
  5. C code assistance please
    By lotus in forum C Programming
    Replies: 7
    Last Post: 05-25-2002, 02:29 AM

Tags for this Thread