How to access a TXT mbr in C? - IBM AS400

This is a discussion on How to access a TXT mbr in C? - IBM AS400 ; here is my code: #iinclude int main(int argc,char * argv[]) { FILE *fp; #pragma convert(37) fp=fopen("/QSYS.LIB/TESTC.LIB/SRC.FILE/INPUT.MBR","wb+"); #pragma convert(0) if (!fp) { printf("error to open the mbr: %s",strerror(errno) ); return 1; } fprintf(fp,"----------------------------------------------------- \n"); fprintf(fp,"----------------------------------------------------- \n"); fprintf(fp,"----------------------------------------------------- \n"); fprintf(fp,"----------------------------------------------------- \n"); fprintf(fp,"----------------------------------------------------- ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: How to access a TXT mbr in C?

  1. How to access a TXT mbr in C?

    here is my code:

    #iinclude
    int main(int argc,char * argv[])
    {
    FILE *fp;
    #pragma convert(37)
    fp=fopen("/QSYS.LIB/TESTC.LIB/SRC.FILE/INPUT.MBR","wb+");
    #pragma convert(0)
    if (!fp)
    {
    printf("error to open the mbr: %s",strerror(errno) );
    return 1;
    }
    fprintf(fp,"-----------------------------------------------------
    \n");
    fprintf(fp,"-----------------------------------------------------
    \n");
    fprintf(fp,"-----------------------------------------------------
    \n");
    fprintf(fp,"-----------------------------------------------------
    \n");
    fprintf(fp,"-----------------------------------------------------
    \n");
    fprintf(fp,"-----------------------------------------------------
    \n");
    fprintf(fp,"-----------------------------------------------------
    \n");
    fprintf(fp,"-----------------------------------------------------
    \n");
    fprintf(fp,"-----------------------------------------------------
    \n");
    fprintf(fp,"-----------------------------------------------------
    \n");

    fclose(fp);
    return 0;
    }






    here is input.mbr

    -----------------------------------------------------

    -------------------------

    ----------------------------

    --------------------------------------------------

    ---

    -----------------------------------------------------

    --------------------

    ---------------------------------

    ---------------------------------------------

    --------

    -----------------------------------------------------

    ---------------

    --------------------------------------

    ----------------------------------------

    -------------

    -----------------------------------------------------


    I want to know why does this happen? It seemed that every 80
    charactors, s400 will add a for me.

    how can i make the program output in INPUT.MBR like this:
    -----------------------------------------------------
    -----------------------------------------------------
    -----------------------------------------------------
    -----------------------------------------------------
    -----------------------------------------------------
    -----------------------------------------------------
    -----------------------------------------------------
    -----------------------------------------------------
    ....

    thanks!


  2. Re: How to access a TXT mbr in C?

    On Jun 21, 9:14 am, Alan wrote:
    > here is my code:
    >
    > #iinclude
    > int main(int argc,char * argv[])
    > {
    > FILE *fp;
    > #pragma convert(37)
    > fp=fopen("/QSYS.LIB/TESTC.LIB/SRC.FILE/INPUT.MBR","wb+");
    > #pragma convert(0)
    > if (!fp)
    > {
    > printf("error to open the mbr: %s",strerror(errno) );
    > return 1;
    > }
    > fprintf(fp,"-----------------------------------------------------
    > ...
    > fprintf(fp,"-----------------------------------------------------
    > \n");
    >
    > fclose(fp);
    > return 0;
    >
    > }
    >
    > here is input.mbr
    >
    > -----------------------------------------------------
    >
    > -------------------------
    >
    > ...
    > -----------------------------------------------------
    >
    > I want to know why does this happen? It seemed that every 80
    > charactors, s400 will add a for me.
    >
    > how can i make the program output in INPUT.MBR like this:
    > -----------------------------------------------------
    > ...
    > -----------------------------------------------------
    > ...
    >
    > thanks!


    A 'TXT' member will most likely have a fixed record length, its part
    of a database table not a stream file. ie every x characters there is
    a hard linebreak. If you do dspffd against your file then you will
    have more idea. If not then post the basic dspffd result here &
    someone who has used c like this can help. The record length may not
    be fixed if there are varying length fields, but I dont use these so
    cant be sure.

    Jonathan


  3. Re: How to access a TXT mbr in C?

    il 21/06/2007 10.14, Scrive Alan 38280784:
    > here is my code:
    >
    > #iinclude
    > int main(int argc,char * argv[])
    > {
    > FILE *fp;
    > #pragma convert(37)
    > fp=fopen("/QSYS.LIB/TESTC.LIB/SRC.FILE/INPUT.MBR","wb+");
    > #pragma convert(0)
    > I want to know why does this happen? It seemed that every 80
    > charactors, s400 will add a for me.

    It's a record file, not a stream one, try with "wb, type=record,
    recfm=f, lrecl=80"
    I'm curious, why did you enclosed fopen between #pragma convert?
    That's a directive to inform the compiler that literals has to be
    assumed as cp 37, in your fopen there's nothing to convert from an
    ebcdic code page to another.
    --
    Dr.Ugo Gagliardelli,Modena,ItalyCertifiedUindoscrasherAñe joAlcoolInside
    Spaccamaroni andate a cagare/Spammers not welcome/Spammers vão à merda
    Spamers iros a la mierda/Spamers allez vous faire foutre/Spammers loop
    schijten/Spammers macht Euch vom Acker/Spamerzy wypierdalac'

  4. Re: How to access a TXT mbr in C?

    On Jun 22, 12:58 am, "Dr.UgoGagliardelli"
    wrote:
    > il 21/06/2007 10.14, Scrive Alan 38280784:> here is my code:
    >
    > > #iinclude
    > > int main(int argc,char * argv[])
    > > {
    > > FILE *fp;
    > > #pragma convert(37)
    > > fp=fopen("/QSYS.LIB/TESTC.LIB/SRC.FILE/INPUT.MBR","wb+");
    > > #pragma convert(0)
    > > I want to know why does this happen? It seemed that every 80
    > > charactors, s400 will add a for me.

    >
    > It's a record file, not a stream one, try with "wb, type=record,
    > recfm=f, lrecl=80"

    thanks for this, it help

    > I'm curious, why did you enclosed fopen between #pragma convert?
    > That's a directive to inform the compiler that literals has to be
    > assumed as cp 37, in your fopen there's nothing to convert from an
    > ebcdic code page to another.

    the string of filepath "/Qsys....." needs this.
    > --
    > Dr.Ugo Gagliardelli,Modena,ItalyCertifiedUindoscrasherAñe joAlcoolInside
    > Spaccamaroni andate a cagare/Spammers not welcome/Spammers vão à merda
    > Spamers iros a la mierda/Spamers allez vous faire foutre/Spammers loop
    > schijten/Spammers macht Euch vom Acker/Spamerzy wypierdalac'




  5. Re: How to access a TXT mbr in C?

    il 22/06/2007 9.44, Scrive Alan 36721672:
    > On Jun 22, 12:58 am, "Dr.UgoGagliardelli"
    > wrote:
    >> il 21/06/2007 10.14, Scrive Alan 38280784:> here is my code:
    >>
    >>> #iinclude
    >>> int main(int argc,char * argv[])
    >>> {
    >>> FILE *fp;
    >>> #pragma convert(37)
    >>> fp=fopen("/QSYS.LIB/TESTC.LIB/SRC.FILE/INPUT.MBR","wb+");
    >>> #pragma convert(0)
    >>> I want to know why does this happen? It seemed that every 80
    >>> charactors, s400 will add a for me.

    >> It's a record file, not a stream one, try with "wb, type=record,
    >> recfm=f, lrecl=80"

    > thanks for this, it help
    >
    >> I'm curious, why did you enclosed fopen between #pragma convert?
    >> That's a directive to inform the compiler that literals has to be
    >> assumed as cp 37, in your fopen there's nothing to convert from an
    >> ebcdic code page to another.

    > the string of filepath "/Qsys....." needs this.

    Maybe your default code page is not a latin-1 one or is not SBCS?


    --
    Dr.Ugo Gagliardelli,Modena,ItalyCertifiedUindoscrasherAñe joAlcoolInside
    Spaccamaroni andate a cagare/Spammers not welcome/Spammers vão à merda
    Spamers iros a la mierda/Spamers allez vous faire foutre/Spammers loop
    schijten/Spammers macht Euch vom Acker/Spamerzy wypierdalac'

+ Reply to Thread