Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Achou.Wang
21st-Century-Examples
提交
a99549a1
2
21st-Century-Examples
项目概览
Achou.Wang
/
21st-Century-Examples
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
2
21st-Century-Examples
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
a99549a1
编写于
9月 20, 2014
作者:
B
Ben
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Split anonymous structs into two examples
上级
eba76a12
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
48 addition
and
16 deletion
+48
-16
dynamic.c
dynamic.c
+3
-4
gsl_distance.c
gsl_distance.c
+3
-4
seamlessthree.c
seamlessthree.c
+34
-0
seamlesstwo.c
seamlesstwo.c
+1
-1
times_table.c
times_table.c
+0
-1
tutorial/divisions.c
tutorial/divisions.c
+3
-3
tutorial/do_while.c
tutorial/do_while.c
+0
-1
tutorial/item_seven.c
tutorial/item_seven.c
+1
-1
tutorial/pointer_in.c
tutorial/pointer_in.c
+1
-1
unicode.c
unicode.c
+2
-0
未找到文件。
dynamic.c
浏览文件 @
a99549a1
/* Compile with:
LDLIBS="-lm -ldl -lreadline" CFLAGS="-g -Wall -std=gnu11 -O3" make dynamic
*/
#define _GNU_SOURCE //cause stdio.h to include asprintf
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
...
...
@@ -12,12 +11,12 @@ void get_a_function(){
fprintf
(
f
,
"#include <math.h>
\n
"
"double fn(double in){
\n
"
);
char
*
a_line
=
NULL
;
char
*
header
=
">>double fn(double in){
\n
>> "
;
char
*
prompt
=
">>double fn(double in){
\n
>> "
;
do
{
free
(
a_line
);
a_line
=
readline
(
header
);
a_line
=
readline
(
prompt
);
fprintf
(
f
,
"%s
\n
"
,
a_line
);
header
=
">> "
;
prompt
=
">> "
;
}
while
(
strcmp
(
a_line
,
"}"
));
fclose
(
f
);
}
...
...
gsl_distance.c
浏览文件 @
a99549a1
...
...
@@ -12,7 +12,7 @@ double one_dist(gsl_vector *v1, void *v2){
long
double
distance
(
apop_data
*
data
,
apop_model
*
model
){
gsl_vector
*
target
=
model
->
parameters
->
vector
;
return
-
apop_map_sum
(
data
,
.
fn_vp
=
one_dist
,
.
param
=
target
,
.
part
=
'r'
);
return
-
apop_map_sum
(
data
,
.
fn_vp
=
one_dist
,
.
param
=
target
);
}
apop_model
*
min_distance
=
&
(
apop_model
){
...
...
@@ -25,9 +25,8 @@ int main(){
2
.
9
,
8
.
6
,
-
1
.
3
,
3
.
7
,
2
.
9
,
1
.
1
);
Apop_model_add_group
(
min_distance
,
apop_mle
,
.
method
=
APOP_SIMPLEX_NM
,
Apop_model_add_group
(
min_distance
,
apop_mle
,
.
method
=
"NM simplex"
,
.
tolerance
=
1e-5
);
Apop_model_add_group
(
min_distance
,
apop_parts_wanted
);
apop_model
*
est
=
apop_estimate
(
locations
,
min_distance
);
apop_model
*
est
=
apop_estimate
(
locations
,
min_distance
);
apop_model_show
(
est
);
}
seamlessthree.c
0 → 100644
浏览文件 @
a99549a1
/* Compile with:
make LDLIBS='-lm' CFLAGS="-g -Wall -std=gnu11" seamlessthree
*/
#include <stdio.h>
#include <math.h>
typedef
struct
point
{
double
x
,
y
;
}
point
;
typedef
struct
{
union
{
struct
{
double
x
,
y
;
};
point
p2
;
};
double
z
;
}
threepoint
;
double
length
(
point
p
){
return
sqrt
(
p
.
x
*
p
.
x
+
p
.
y
*
p
.
y
);
}
double
threelength
(
threepoint
p
){
return
sqrt
(
p
.
x
*
p
.
x
+
p
.
y
*
p
.
y
+
p
.
z
*
p
.
z
);
}
int
main
(){
threepoint
p
=
{.
x
=
3
,
.
y
=
0
,
.
z
=
4
};
printf
(
"p is %g units from the origin
\n
"
,
threelength
(
p
));
double
xylength
=
length
(
p
.
p2
);
printf
(
"Its projection onto the XY plane is %g units from the origin
\n
"
,
xylength
);
}
seamlesstwo.c
浏览文件 @
a99549a1
/* Compile with:
make LDLIBS='-lm' CFLAGS="-g -Wall -std=gnu11 -
-
ms-extensions" seamlesstwo
make LDLIBS='-lm' CFLAGS="-g -Wall -std=gnu11 -
f
ms-extensions" seamlesstwo
*/
#include <stdio.h>
#include <math.h>
...
...
times_table.c
浏览文件 @
a99549a1
...
...
@@ -9,7 +9,6 @@ void matrix_cross_base(double *list1, double *list2){
int
count1
=
0
,
count2
=
0
;
while
(
!
isnan
(
list1
[
count1
]))
count1
++
;
while
(
!
isnan
(
list2
[
count2
]))
count2
++
;
if
(
!
count1
||
!
count2
)
{
printf
(
"missing data."
);
return
;}
for
(
int
i
=
0
;
i
<
count1
;
i
++
){
for
(
int
j
=
0
;
j
<
count2
;
j
++
)
...
...
tutorial/divisions.c
浏览文件 @
a99549a1
#include <stdio.h>
int
main
(){
printf
(
"
3./5=%g
\n
"
,
3
.
/
5
);
printf
(
"
3/5=%i
\n
"
,
3
/
5
);
printf
(
"
3%%5=%i
\n
"
,
3
%
5
);
printf
(
"
13./5=%g
\n
"
,
1
3
.
/
5
);
printf
(
"
13/5=%i
\n
"
,
1
3
/
5
);
printf
(
"
13%%5=%i
\n
"
,
1
3
%
5
);
}
tutorial/do_while.c
浏览文件 @
a99549a1
...
...
@@ -6,7 +6,6 @@ void loops(int max){
printf
(
"Hello #%i
\n
"
,
i
);
i
++
;
}
while
(
i
<
max
);
//Note the semicolon.
}
int
main
(){
...
...
tutorial/item_seven.c
浏览文件 @
a99549a1
...
...
@@ -7,6 +7,6 @@ int main(){
char
string
[
len
];
intlist
[
7
]
=
7
;
snprintf
(
string
,
20
,
"Item seven is %i."
,
intlist
[
7
]);
snprintf
(
string
,
len
,
"Item seven is %i."
,
intlist
[
7
]);
printf
(
"string says: <<%s>>
\n
"
,
string
);
}
tutorial/pointer_in.c
浏览文件 @
a99549a1
...
...
@@ -6,7 +6,7 @@ void double_in(int *in){
}
int
main
(){
int
*
x
=
malloc
(
sizeof
(
int
))
;
int
x
[
1
]
;
*
x
=
10
;
double_in
(
x
);
printf
(
"x now points to %i.
\n
"
,
*
x
);
...
...
unicode.c
浏览文件 @
a99549a1
...
...
@@ -40,6 +40,7 @@ int main(int argc, char **argv){
char
*
ucs
=
localstring_to_utf8
(
string_from_file
(
argv
[
1
]));
Stopif
(
!
ucs
,
return
1
,
"Exiting."
);
FILE
*
out
=
fopen
(
"uout.html"
,
"w"
);
Stopif
(
!
out
,
return
1
,
"Couldn't open uout.html for writing."
);
fprintf
(
out
,
"<head><meta http-equiv=
\"
Content-Type
\"
"
...
...
@@ -48,6 +49,7 @@ int main(int argc, char **argv){
fprintf
(
out
,
"Its Unicode encoding required %zu bytes.<br>"
,
strlen
(
ucs
));
fprintf
(
out
,
"Here it is, with each space-delimited element on a line "
"(with commentary on the first character):<br>"
);
ok_array
*
spaced
=
ok_array_new
(
ucs
,
"
\n
"
);
for
(
int
i
=
0
;
i
<
spaced
->
length
;
i
++
,
(
spaced
->
elements
)
++
){
fprintf
(
out
,
"%s"
,
*
spaced
->
elements
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录