-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstore_triang_files.c
More file actions
108 lines (94 loc) · 1.26 KB
/
store_triang_files.c
File metadata and controls
108 lines (94 loc) · 1.26 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/// store data of < files > in another file.
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//////////////////
typedef struct rc
{
int r;
int c;
}RC;
//////////////////////////////
struct rc lengthy(FILE *fs)
{
int c=0,f=0,c1=0;
RC x;
char ch;
while( (ch=fgetc(fs))!=-1 )
{
c++;
if(ch=='<')
{
f++;
if(c>c1)
c1=c;
c=0;
}
}
x.r=f;
x.c=c1;
return x;
}
//////////////////////////////////////////////
void main(int argc,char **argv)
{
int i,j,k,c;
char **p,ch;
FILE *fp,*fs,*fd;
RC x;
if(argc!=2)
{
printf("\nMissing operands..\nUsage: ./a.out file\n");
return;
}
fs=fopen(argv[1],"r");
if(fs==0)
{
printf("error: asd: No such file or directory.\n");
return;
}
x=lengthy(fs);
printf("r=%d c=%d\n",x.r,x.c);
rewind(fs);
p=malloc(sizeof(char*)*x.r);
for(i=0;i<x.r;i++)
p[i]=malloc(sizeof(char)*x.c);
//fd=fopen(argv[2],"a");
i=0;
j=0;
while( (ch=fgetc(fs))!=-1 )
{
if(ch=='<')
{
while((ch=fgetc(fs))!='>')
{
p[i][j]=ch;
j++;
}
if(ch=='>')
{
p[i][j]='\0';
i++;
j=0;
}
}
}
for(i=0;i<x.r;i++)
printf("%s\n",p[i]);
fclose(fs);
fd=fopen(argv[1],"w");
fclose(fd);
fd=fopen(argv[1],"a");
for(i=0;i<x.r;i++)
{
if( fp=fopen(p[i],"r") )
{
while( (ch=fgetc(fp))!=-1 )
fputc(ch,fd);
}
else
{
printf("err: No such file %s\n",p[i]);
}
}
}