Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2539779
  • 博文数量: 351
  • 博客积分: 76
  • 博客等级: 上将
  • 技术积分: 3555
  • 用 户 组: 普通用户
  • 注册时间: 2004-11-13 21:27
文章分类

全部博文(351)

文章存档

2013年(1)

2012年(4)

2011年(7)

2010年(16)

2009年(34)

2008年(34)

2007年(34)

2006年(68)

2005年(82)

2004年(71)

分类: C/C++

2004-12-14 17:08:14

example c code - 给二维字符串数组参数赋值

一直弄不太懂给二维字符串数组参数赋值的问题,
以前写过一些,总出问题,最后往往都用一个struct给代替了。
今天向别人请教之后,写了个简单的例子。

1 /*
2 * str_array.c - test for assigning data to a 2 dimensional string array parameter
3 *
4 * Author: zhou weicheng at 163 dot com
5 * Date: 2004/12/14
6 */
7
8 #include
9
10 #define STR_SIZE 255
11
12 void write_array(char str_arry[][STR_SIZE])
13 {
14 sprintf(str_arry[0], "test0");
15 sprintf(str_arry[1], "test1");
16 sprintf(str_arry[2], "test2");
17 }
18
19 int main(void)
20 {
21 char str_arry[3][STR_SIZE];
22
23 write_array(str_arry);
24
25 printf("str[0]: %sn", str_arry[0]);
26 printf("str[1]: %sn", str_arry[1]);
27 printf("str[2]: %sn", str_arry[2]);
28
29 exit(0);
30 }

阅读(2296) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~