-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprog.c.c
More file actions
67 lines (64 loc) · 1.3 KB
/
prog.c.c
File metadata and controls
67 lines (64 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdio.h>
#include <stdlib.h>
#define MAX 1000
int lettura(char file[],float vettx[],float vetty[]){
int i=0;
FILE *fp;
char carattere;
fp=fopen(file,"r");
while(!feof(fp)){
fscanf(fp,"%c",&carattere);
if(carattere=='X'){
fscanf(fp,"%f",&vettx[i]);
}
if(carattere=='Y'){
fscanf(fp,"%f",&vetty[i]);
i++;
}
}
fclose(fp);
return i;
}
void bubble_sort(float vettx[],float vetty[],int dim){
int i,j;
float tmpx,tmpy;
for(i=dim-1;i>0;i--)
{
for(j=0;j<i;j++)
{
if(vettx[j]>vettx[j+1])
{
tmpx=vettx[j+1];
vettx[j+1]=vettx[j];
vettx[j]=tmpx;
tmpy=vetty[j+1];
vetty[j+1]=vetty[j];
vetty[j]=tmpy;
}
}
}
}
void scrittura(char file[],float vettx[],float vetty[],int dim){
FILE *fp;
int i;
fp=fopen(file,"w");
fprintf(fp,"G90\nG21\n");
for(i=1;i<dim;i++){
fprintf(fp,"X%f ",vettx[i]);
fprintf(fp,"Y%f\n",vetty[i]);
}
fprintf(fp,"G0 X0.000 Y0.000\nM05\nM02");
}
int main(){
char file[40];
float vettx[MAX],vetty[MAX];
int dim;
printf("Nome del file: ");
scanf("%s",file);
dim=lettura(file,vettx,vetty);
printf("Nome del file dove scrivere i risultati: ");
scanf("%s",file);
bubble_sort(vettx,vetty,dim);
scrittura(file,vettx,vetty,dim);
return 0;
}