這個C語言程式,可以叫AutoCAD自動畫圖
by 高顯忠, 2010-11-11 16:48, Views(3607)
底下這個程式,讀 excel 產生的 text file,
使用 空格分離 不同欄位。
產生 AutoCAD script file,
即可 教AutoCAD 自動產生圖形物件
#include "stdafx.h"
#include <process.h>
// ------------------------------
int main(int argc, char* argv[])
{
FILE *f1, *f2;
// open the input and output file
if ((f1= fopen("book2a.txt", "rt")) == NULL) {
printf("\n *** error of fopen() of f1\n");
system("pause");
exit(1);
}
if ((f2= fopen("T0435.scr", "wt")) == NULL) {
printf("\n *** error of fopen() of f2\n");
system("pause");
exit(1);
}
printf("\n OK for fopen() of f1 and f2, at 04:37\n");
system("pause");
// ------------------------------
// read the data from file
int ct= -1, no, i;
double x[100], y[100];
while (!feof(f1)) {
ct++;
no= fscanf(f1, "%lf %lf", &x[ct], &y[ct]);
if (no != 2) {
ct--;
break;
}
}// end of while
fprintf(f2, "spline\n");
for (i=0;i<=ct;i++) {
printf("%5d, %10.6lf, %10.6lf\n", i, x[i], y[i]);
fprintf(f2, "%.6lf,%.6lf\n", x[i], y[i]);
}
fprintf(f2, "\n\n\n");
fclose(f1);
fclose(f2);
return 0;
}