GRASS Programmer's Manual
6.5.svn(2014)-r66266
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
try2.c
Go to the documentation of this file.
1
/*
2
** Written by David Gerdes US Army Construction Engineering Research Lab
3
** April 1992
4
** Copyright 1992 USA-CERL All rights reserved.
5
**
6
*/
7
8
9
/*
10
** read from stdin and each line into a linked list of chars
11
** then print it back out. if there is any argument specified
12
** the lines will be printed out reversed.
13
*/
14
15
#include <stdio.h>
16
#include <grass/linkm.h>
17
18
struct
link
19
{
20
char
let
;
21
struct
link
*
next
;
22
};
23
24
int
main
(
int
argc,
char
*argv[])
25
{
26
register
int
i;
27
VOID_T
*head;
28
struct
link
List, *tmp, *p;
29
int
rev = 0;
30
char
buf
[4096];
31
32
if
(argc == 2)
33
rev = 1;
34
35
36
List.
next
=
NULL
;
37
List.
let
=
' '
;
38
39
40
link_set_chunk_size
(1);
41
head = (
VOID_T
*)
link_init
(
sizeof
(
struct
link
));
42
43
44
while
(
NULL
!= gets(buf)) {
45
for
(i = 0; buf[i] !=
'\0'
; i++) {
46
tmp = (
struct
link
*)
link_new
(head);
47
tmp->
let
= buf[i];
48
if
(rev)
49
add_link_rev
(&List, tmp);
50
else
51
add_link
(&List, tmp);
52
}
53
54
dumplist
(&List);
55
56
p = List.
next
;
57
58
while
(p !=
NULL
&& p->
next
!=
NULL
) {
59
tmp = p->
next
;
60
link_dispose
(head, p);
61
p = tmp;
62
}
63
List.
next
=
NULL
;
64
}
65
66
link_cleanup
(head);
67
68
exit(0);
69
}
70
71
int
add_link_rev
(
struct
link
*List,
struct
link
*
link
)
72
{
73
struct
link *p;
74
75
p = List->
next
;
76
List->
next
= link;
77
link->
next
= p;
78
}
79
80
int
add_link
(
struct
link
*List,
struct
link
*
link
)
81
{
82
struct
link *p;
83
84
p = List;
85
while
(p->
next
!=
NULL
)
86
p = p->
next
;
87
p->
next
= link;
88
link->
next
=
NULL
;
89
}
90
91
int
dumplist
(
struct
link
*List)
92
{
93
struct
link
*p;
94
95
p = List->
next
;
96
while
(p !=
NULL
) {
97
putchar(p->
let
);
98
p = p->
next
;
99
}
100
putchar(
'\n'
);
101
}
VOID_T
#define VOID_T
Definition:
qtree.h:17
link_init
struct link_head * link_init(int size)
Definition:
linkm/init.c:40
link_new
struct link_head * link_new(struct link_head *Head)
Definition:
new.c:12
link::next
struct link * next
Definition:
linkm.c:21
link_cleanup
void link_cleanup(struct link_head *Head)
Definition:
linkm/init.c:64
link_set_chunk_size
void link_set_chunk_size(int size)
Definition:
linkm/init.c:30
link::let
char let
Definition:
linkm.c:20
main
int main(int argc, char *argv[])
Definition:
gem/main.c:302
add_link
int add_link(struct link *List, struct link *link)
Definition:
linkm/try.c:75
buf
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
Definition:
g3drange.c:62
link_dispose
void link_dispose(struct link_head *Head, VOID_T *ptr)
Definition:
dispose.c:10
NULL
return NULL
Definition:
dbfopen.c:1394
link
Definition:
linkm.c:18
add_link_rev
int add_link_rev(struct link *List, struct link *link)
Definition:
linkm/try.c:66
dumplist
int dumplist(struct link *List)
Definition:
linkm/try.c:86
lib
linkm
try2.c
Generated on Sat Jan 2 2016 01:46:49 for GRASS Programmer's Manual by
1.8.5