uot;);
fclose(fout);
// 产 生CREATE TABEL. 的SQL 语 句
strcpy(sqlload,argv);
strcat(sqlload,".sql");
if ((fout=fopen(sqlload,"w")) == NULL)
{ cout < < "Cannot open file " < < sqlload < < endl;
return -1 ;
}
fprintf(fout, "create table %s (\n", argv);
for(i=0;i< field_num;i++)
{ fprintf(fout,"%11s",dbffield[i].name);
switch (dbffield[i].type)
{ case ''C'': //字符型
fprintf(fout, " CHAR(%d)",dbffield[i].length);
break;
case ''L'': //逻辑型
fprintf(fout, " CHAR(1)");
break;
case ''N'': //数字型
if (dbffield[i].dec==0)
fprintf(fout," NUMBER(%d)", dbffield[i].length) ;
else
fprintf(fout, " NUMBER(%d,%d)",
dbffield[i].length-1, dbffield[i].dec);
break;
case ''D'': // 日 期 型
fprintf(fout, " DATE");;
break;
default:
break;
}
if (i< field_num - 1)
fprintf(fout, ",\n");
}
fprintf(fout, ")\n");
fclose(fout);
// 产生SQL*Loader数据文件
strcpy(sqlload,argv);
strcat(sqlload,".txt");
if((fout=fopen(sqlload,"w")) == NULL)
{ cout < < "Cannot open file " < < sqlload < < endl;
return -1 ;
}
fseek(fp,dbfhead- >head_length,SEEK_SET);
for(i=0;i< dbfhead- >record_num;i++)
{ fread(buf,dbfhead- >field_length,1,fp);
buf[dbfhead- >field_length] =''\0'';
fprintf(fout,"%s\n", buf+1); //skip记录首字节(删除标志)
}
fclose(fout);
fclose(fp);
delete sqlload;
return 0 ;
}