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函數(shù)。該函數(shù)第一個是char buf[maxn]的數(shù)組名稱buf,第二個是maxn,最多能存下maxn-1個字符,最后一個是'\0'。
20 該函數(shù)遇到換行符號停止讀取
21 */
1 #include <stdio.h>
2
3 void print(int *, int, int);
4 int main() {
5
6
7 int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
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) == 0) break; // 重復(fù)則退出
14 }
15 return 0;
16 }
17
18 // 輸出一個環(huán),該環(huán)的初始位置為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