Text import
От | Vijay Deval |
---|---|
Тема | Text import |
Дата | |
Msg-id | 3B8DB2DB.2C0EE13D@giaspn01.vsnl.net.in обсуждение исходный текст |
Список | 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 по дате отправления: