f(sixleaves) = sixleaves

重剑无锋 大巧不工

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  95 随笔 :: 0 文章 :: 7 评论 :: 0 Trackbacks
 1 #include <stdio.h>
 2 
 3 #define MAXN 1024
 4 char buf[MAXN] = {0};
 5 int main() {
 6 
 7     FILE *fp = fopen("t.txt","r");
 8     if (!fp) return -1;
 9 
10     for (;;) {
11         
12         char * p = fgets(buf, MAXN, fp);
13         if (!p) break;
14         printf("%s",p);
15     }
16     fclose(fp);
17     return 0;
18 }
19 /*之所以用fgets是因为fscanf有scanf的特性,遇到空白符就会终止读取。所以要读取一行最好是用fgets函数。该函数第一个是char buf[maxn]的数组名称buf,第二个是maxn,最多能存下maxn-1个字符,最后一个是'\0'。
20 该函数遇到换行符号停止读取
21 */
 1 #include <stdio.h>
 2 
 3 void print(int *intint);
 4 int main() {
 5 
 6     
 7     int a[] = {12345678910};
 8     int t = 10;
 9     // 枚举起始位置
10     for (int p = 0;; p -= 2) {
11         
12         print(a, t, p);
13         if (p != 0 && ((p + t) % t) == 0break// 重复则退出
14     }
15     return 0;
16 }
17 
18 // 输出一个环,该环的初始位置为p,周期为t
19 void print(int *a, int t, int p) {
20     
21     for (int i = 0; i < 10; i++) {
22         p = (p + t) % t;
23         printf("%d ", a[p]);
24         p++;
25         
26     }
27     putchar('\n');
28 }
29 
30 //该帖子地址http://bbs.bccn.net/thread-442590-1-1.html

about me,copy the url to your brower~.
http://bbs.bccn.net/space-uid-814155.html
posted on 2015-03-13 21:23 swp 阅读(96) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理