2006-04-04 16:50:56sjgau
叫 AutoCAD 自動化函數圖形的程式
#include <stdio.h>
#include <math.h>
#include <conio.h>
#include <process.h>
#include <string.h>
// ----------------------------------------------
// rmv_blk( s2);
void rmv_blk(char *s1)
{
char s2[100];
strcpy(s2, s1);
int l1= strlen(s2);
int j= -1;
for (int i=0;i<l1;i++) {
if (s2[i] != ' ') {
s1[++j]= s2[i];
}
}
s1[j]= ' ';
}// end of rmv_blk()
// ----------------------------------------------
void main(int argc, char *argv[])
{
FILE *f1, *f2;
char s1[100], s2[100];
// ----------------------------------------------
if (argc != 3) {
printf("Usage: txt2scr file1.txt file2.scr [Enter]");
_getch();
exit(1);
}
// ----------------------------------------------
if ((f1= fopen(argv[1], "rt")) == NULL) {
printf("*** error of fopen() for %sn", argv[1]);
_getch();
exit(1);
}
if ((f2= fopen(argv[2], "wt")) == NULL) {
printf("*** error of fopen() for %sn", argv[2]);
_getch();
exit(1);
}
// ----------------------------------------------
int ct1= 0, l1;
double x, y;
fprintf(f2, "PLINEn");
while (!feof(f1)) {
fgets(s1, 99, f1);
if (feof(f1)) {
break;
}
l1= strlen(s1);
if (l1 > 0) {
ct1++;
sscanf(s1, "%lg %lg", &x, &y);
sprintf(s2, "%13.7lg, %13.7lgn", x, y);
l1= strlen(s2);
rmv_blk(s2);
fprintf(f2, "%sn", s2);
}
}
fprintf(f2, "n");
printf("nDone! points= %dn", ct1);
fclose(f1);
fclose(f2);
}// end of main()
#include <math.h>
#include <conio.h>
#include <process.h>
#include <string.h>
// ----------------------------------------------
// rmv_blk( s2);
void rmv_blk(char *s1)
{
char s2[100];
strcpy(s2, s1);
int l1= strlen(s2);
int j= -1;
for (int i=0;i<l1;i++) {
if (s2[i] != ' ') {
s1[++j]= s2[i];
}
}
s1[j]= ' ';
}// end of rmv_blk()
// ----------------------------------------------
void main(int argc, char *argv[])
{
FILE *f1, *f2;
char s1[100], s2[100];
// ----------------------------------------------
if (argc != 3) {
printf("Usage: txt2scr file1.txt file2.scr [Enter]");
_getch();
exit(1);
}
// ----------------------------------------------
if ((f1= fopen(argv[1], "rt")) == NULL) {
printf("*** error of fopen() for %sn", argv[1]);
_getch();
exit(1);
}
if ((f2= fopen(argv[2], "wt")) == NULL) {
printf("*** error of fopen() for %sn", argv[2]);
_getch();
exit(1);
}
// ----------------------------------------------
int ct1= 0, l1;
double x, y;
fprintf(f2, "PLINEn");
while (!feof(f1)) {
fgets(s1, 99, f1);
if (feof(f1)) {
break;
}
l1= strlen(s1);
if (l1 > 0) {
ct1++;
sscanf(s1, "%lg %lg", &x, &y);
sprintf(s2, "%13.7lg, %13.7lgn", x, y);
l1= strlen(s2);
rmv_blk(s2);
fprintf(f2, "%sn", s2);
}
}
fprintf(f2, "n");
printf("nDone! points= %dn", ct1);
fclose(f1);
fclose(f2);
}// end of main()