读书共享 Primer Plus C-part 7

第十章  数组和指针

1.关于二维数组跟指针

#include<stdio.h>


int main()

{
   int arrs [3][4]={{1,2,3,4},{5,6,7,8},{9,10,11,12}};
   int i = 0;
   for(i=0;i< 10 ;i++)

   {
     printf("%d 
",**arrs+i);

   }

}

   上述代码:可以说明二维数组的指针的排序以及使用

  按行打 

    

#include<stdio.h>


int main()

{
   int arrs [3][4]={{1,2,3,4},{5,6,7,8},{9,10,11,12}};
   int i = 0;
   for(i=0;i< 3 ;i++)

   {
     printf("%d 
",*(arrs[1]+i));

   }


}

按 列打

#include<stdio.h>


int main()

{
   int arrs [3][4]={{1,2,3,4},{5,6,7,8},{9,10,11,12}};
   int i = 0;
   for(i=0;i< 3 ;i++)

   {
     printf("%d 
",**arrs+i*4);

   }
}
第十一章 字符串和字符串函数
  • 关于字符串的2种表达方式
char heart[]="liuchaunwu";
char * head = "liuchuanwu";
head++; //OK
haart++; //NOK

 1 #include<stdio.h>
 2 
 3 
 4 int main()
 5 {
 6 
 7     char name[50] ={0};
 8 
 9     puts("what is your name");
10 
11     //gets(name);
12     char heart[] = "liu chuan wu";
13     char * head = "liu chuan wu";
14 
15     while(*head!='')
16     {
17      putchar(*head++);
18     }
19     putchar('
');
20 
21      while(*heart!='')
22     {
23       putchar(*heart++);
24     }
25      putchar('
');
26 
27 
28 
29 }

二维数组的打印

 1 #include<stdio.h>
 2 int main()
 3 {
 4     char *str[100]={
 5    "what is your name? ",
 6    "my name is liuchuanwu.",
 7    "do you love me?",
 8    "I am so sorry!"
 9 
10    };
11   int i =0;
12   for(;i<4;i++)
13   {
14    printf("%s 
",(str[i]));
15 
16   }
17 
18 }
  •  关于  gets fgets getchar

           gets:单个入参,不检查是否足够的空间

           fget:检查空间,针对I/O设计灵活性不足

           getchar:针对单个字符进行读取。

  •   关于strcat stncat

           strcat  字符串追加

           stncat 考虑字符串的空间问题。简单说安全与不安全的问题

  • strcmp 与strncmp

           srrcmp(str1,str2 ) str1=str2:0 str1>str2:1 str1<str2:-1

          strncmp比较前几个字符

原文地址:https://www.cnblogs.com/liuchuanwu/p/7118417.html