Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > alt.comp.os.windows-10 > #164898

Re: How to insert contents of a file (or a line of text) at a given location inside hundreds of text files?

From Herbert Kleebauer <klee@unibwm.de>
Newsgroups alt.comp.os.windows-10, alt.comp.microsoft.windows, alt.msdos.batch
Subject Re: How to insert contents of a file (or a line of text) at a given location inside hundreds of text files?
Date 2022-12-20 19:15 +0100
Organization Aioe.org NNTP Server
Message-ID <tnsu3b$941$1@gioia.aioe.org> (permalink)
References <tnp4n3$jrm$1@gioia.aioe.org> <tnp59a$7l7n$1@dont-email.me> <tnpek5$8f19$1@dont-email.me>

Cross-posted to 3 groups.

Show all headers | View raw


On 19.12.2022 11:32, Paul wrote:

> With C, there would be a temptation to write some
> low level text handlers, that a textual processor
> would already have. Maybe you can find a library for C
> to act as an assistant, so it's not an impossibility.

Just searched for a small C compiler which doesn't need
to be installed so you can store it on an USB stick and
use it on any computer.

https://download.savannah.gnu.org/releases/tinycc/
https://download.savannah.gnu.org/releases/tinycc/tcc-0.9.27-win32-bin.zip

Just put the content of the zip file in a new folder
and all you have to do is:

tcc your_program.c

It directly creates the binary your_program.exe

And here a small C program which inserts text after
a given number of lines in a file:

________________________________________________________

/* usage: ins infile outfile                        */
/* after line number LINE the text TEXT is inserted */

#define LINE 5
#define TEXT "user\npass\n"

/************************************************************************
external functions used:  getc(); putc(); fopen(); fclose(); exit();
************************************************************************/

#include <stdio.h>
FILE *in, *out, *fopen();

void out_string();
void print_string();
void ende();
void exit();

main(nargs,args) int nargs; char *args[];
{if (nargs!=3) ende(1);
  in  = fopen(args[1],"rb"); if (in==NULL)  ende(2);
  out = fopen(args[2],"wb"); if (out==NULL) ende(3);

  int i,n=0;
  while ( (i=getc(in)) != EOF)
  {putc(i,out);
   if (i == 10) n++;
   if (n == LINE)  {n++; out_string(TEXT);}
  }
  ende(0);
}

void out_string(p)   char *p; {while (*p) putc(*p++,out);}
void print_string(p) char *p; {while (*p) putc(*p++,stdout);}

void ende(i) int i;
{static char *(meld[]) = {
/*  0 */ "no errors" ,
/*  1 */ "usage: ins infile outfile" ,
/*  2 */ "can't open input file" ,
/*  3 */ "can't open output file" ,
/*  4 */ "you never should read this" ,
/*  5 */ "you never should read this" ,
/*  6 */ "you never should read this" ,
};

  print_string("\n"); print_string(meld[i]); print_string("\n");
  if (in!=NULL) fclose(in);
  if (out!=NULL) fclose(out);
  exit(0);
}


Back to alt.comp.os.windows-10 | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How to insert contents of a file (or a line of text) at a given location inside hundreds of text files? Andy Burnelli <spam@nospam.com> - 2022-12-19 07:43 +0000
  Re: How to insert contents of a file (or a line of text) at a given location inside hundreds of text files? Jeff Barnett <jbb@notatt.com> - 2022-12-19 00:53 -0700
    Re: How to insert contents of a file (or a line of text) at a given location inside hundreds of text files? Paul <nospam@needed.invalid> - 2022-12-19 05:32 -0500
      Re: How to insert contents of a file (or a line of text) at a given location inside hundreds of text files? Andy Burnelli <spam@nospam.com> - 2022-12-19 16:36 +0000
        Re: How to insert contents of a file (or a line of text) at a given location inside hundreds of text files? Paul <nospam@needed.invalid> - 2022-12-19 12:53 -0500
      Re: How to insert contents of a file (or a line of text) at a given location inside hundreds of text files? Herbert Kleebauer <klee@unibwm.de> - 2022-12-20 19:15 +0100
    Re: How to insert contents of a file (or a line of text) at a given location inside hundreds of text files? Chris <ithinkiam@gmail.com> - 2022-12-20 11:23 +0000
  Re: How to insert contents of a file (or a line of text) at a given location inside hundreds of text files? Andy Burns <usenet@andyburns.uk> - 2022-12-19 09:48 +0000
  Re: How to insert contents of a file (or a line of text) at a given location inside hundreds of text files? "Kerr-Mudd, John" <admin@127.0.0.1> - 2022-12-19 09:50 +0000
    Re: How to insert contents of a file (or a line of text) at a given location inside hundreds of text files? Big Al <Bears@invalid.com> - 2022-12-19 10:42 -0500
  Re: How to insert contents of a file (or a line of text) at a given location inside hundreds of text files? Herbert Kleebauer <klee@unibwm.de> - 2022-12-19 22:51 +0100
  Re: How to insert contents of a file (or a line of text) at a given location inside hundreds of text files? "R.Wieser" <address@not.available> - 2022-12-20 09:16 +0100

csiph-web