c语言的各种技巧

一、参考网址

  1、参考网址1:C 语言的奇技淫巧

  2. 续行符

  3. C语言 续行符 ‘\‘

  4. printf中输出表达式过长换行的几种方式

  5. C语言中的转义字符

  6. C语言中"##"的用法

  7. c语言调用shell方法(system和popen)

二、实践

  1. 续行符的使用(宏定义和字符串),示例如下:

 1 /**
 2  * 功能:测试续行符 \ 和 “
 3  */
 4 
 5 #include <stdio.h>
 6 
 7 #define TEST_STR1  "123456"
 8 #define TEST_STR2  "123" \
 9                     "456"   //宏定义使用续行符,不能省略中间的两个双引号,否则出错
10 #define MYPRINTF(x) printf("%s\n", \
11                             x);  //宏定义使用续行符
12 
13 int main(void)
14 {
15     char *str1 = "hello world!";
16     char *str2 = "hello \
17     world!";                 //不推荐使用此种方式,中间会多出空格符
18     char *str3 = "hello " \
19                 "world!";    //字符串使用续行符
20     char *str4 = "hello "
21                 "world";
22     char *str5 = "hello ""world";   
23     printf("str1=%s\nstr2=%s\nstr3=%s\nstr4=%s\nstr5=%s\n", str1, str2, str3, str4, str5);
24 
25     printf("TEST_STR1=%s\nTEST_STR2=%s\n", TEST_STR1, TEST_STR2);
26     
27     printf("1. parameter is too long, \
28             this is newline\n");
29     printf("2. parameter is too long, "
30             "this is newline\n");
31     printf("3. parameter is too long, " \
32             "this is newline\n");
33     
34     MYPRINTF("bye bye...");
35 }

运行结果如下:

 

posted @ 2019-12-10 10:04  shanyu20  阅读(136)  评论(0编辑  收藏  举报