Text import - Mailing list pgsql-novice

From Vijay Deval
Subject Text import
Date
Msg-id 3B8DB2DB.2C0EE13D@giaspn01.vsnl.net.in
Whole thread Raw
List pgsql-novice
Dear Pete

I have posted one script to insert field saperator into fixed length
fields text file. I feel the following version is better than the
previous.
Vijay

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

#include <stdio.h>

#define FNM 5     /* number of fields */
#define F1 4      /* length of the first field */
#define FS "|"    /* field saperator */
main()
{
 int c,i,len,count;
 int flen[FNM-2];
 flen[0]=45;    /*length of second field */
 flen[1]=40;    /* length of third field */
 flen[2]=40;    /* length of last field not reqd */

 count=0;
 i=0;
 len=F1;
 c=getchar();
 while (c != EOF){

     putchar(c);
     count=count+1;
     c=getchar();


     if (count==len){
         printf("%s",FS);
         len=len+flen[i];
         i=i+1;
     }
     if (c=='\n'){
       count=0;
       i=0;
       len=F1;
       putchar(c);
       c=getchar();
     }
 }
}
-----------------------------------------------------------------------------#include <stdio.h>

#define FNM 5     /* number of fields */
#define F1 4      /* length of the first field */
#define FS "|"    /* field saperator */
main()
{
int c,i,len,count;
int flen[FNM-2];
 flen[0]=45;    /*length of second field */
 flen[1]=40;    /* length of third field */
 flen[2]=40;    /* length of FNM-1 field ; length of last field not reqd */

count=0;
i=0;
 len=F1;
 c=getchar();
 while (c != EOF){

     putchar(c);
     count=count+1;
     c=getchar();


     if (count==len){
     printf("%s",FS);
     len=len+flen[i];
     i=i+1;
     }
     if (c=='\n'){
       count=0;
       i=0;
       len=F1;
       putchar(c);
       c=getchar();
     }
 }
}


pgsql-novice by date:

Previous
From: "Marc G. Fournier"
Date:
Subject: List archives moved and cleaned up ...
Next
From: Jason Tan
Date:
Subject: pl/pgsql recursion/arrays (fwd)