2022.3.27

//  2022.3.27字符串的输入输出
//  由于字符串采用了'\n'标志,字符串的输入输出将变得简单方便
//#include <stdio.h>
//
//int main()
//{
//    char str[100];
//
//    printf(input string : \n);
//    scanf("%s, str"); //scanf("%s",str) 默认以空格分离
//    printf("output:%s\n", str);
//
//    return 0;
//}
//
//1、gets()
//#include <stdio.h>
//char* gets(char* s);
//功能:从标准输入读入字符,并保存到s 指定的内存空间,直到出现换行符或读到文件结尾为止。
//参数:
//s : 字符串首地址
//返回值:
//成功:读入的字符串
//失败:NULL
//
//gets(str) 与 scanf("%s", str) 的区别;
//(1)gets(str)允许输入的字符串含有空格
//(2)scanf("%s", str)不允许含有空格
//注意:由于 scanf() 和 gets() 无法知道字符串 s 大小,必须遇到换行符或读到文件结尾为止
//才接收输入,因此容易导致字符数组越界(缓冲区溢出)的情况
//char str[100];
//printf("请输入str:");
//gets(str);
//printf("str = %s\n", str);
//
// (2) fgets()
//#include <stdio.h>
//char* fgets(char* s, int size, FILE* stream);
//  功能: 从stream 指定的文件内读入字符,保存到s所指定的内存空间,直到出现换行字符,
//         读到文件结尾或是已读了 size-1 个字符为止,最后会自动加上字符"\0"作为字符串结束
//      参数 :
//      s : 字符串
//      size: 指定最大读取字符串的长度(size-1)
//      steam :文件指针:如果读键盘输入的字符串,固定写为 stdin
//      返回值:
//        成功: 成功读取的字符串
//        读到文件尾或出错: NULL

//   字符串操作函数:
//   gets : 获取一个字符串。返回字符串的首地址,可以获取带有 空格的字符串,【不安全】
//        char * gets(char *s)
//     参数: 用来存储字符串的空间地址。
//     返回值: 返回实际获取到的字符串首地址

//    fgets:  获取一个字符串
//      char *fgets(char *s, int size, FILE *stream).
//        参1:  用来存储字符串的空间地址。
//        参2: 描述空间的大小。
//        参3:读取字符串的位置,标准输入: stdin
//       返回值:返回实际获取到的字符串首地址

//   pust: 将一个字符串写到屏幕。printf("%s","hello"); / printf("hello\n"); /puts("hello"); 输出字符串后会自动添加 \n 换行符
//        int puts(const char *s);
//        参1:待写出到屏幕的字符串
//      返回值: 成功:非负数, 失败: -1
//      
//    fputs:  将一个字符串写出到屏幕,输出字符串后,不添加 \n 换行符,
//     int fputs(const char * str, FILE * stream);
//    参1:待写出到屏幕的字符串.  屏幕 ==》 标准输出: stdout
//   参数:写出位置 stdout
//   返回值: 成功:非负数, 失败: -1
//   strlen :
//       size_t strlen(const char *s);
//      参1:待求长度的字符串
//      返回:有效的字符个数。
//  字符串追加:
//     char str1[] = "hello";
//     char str2[] = "world"
// 
//    char str[3] = {0};
// 
// (5) strlen()
// #inclide <string.h>
// size_t strlen(const char *s);
//  功能: 计算指定指定字符串 s 的长度,不包含字符串结束符'\0'.
// 参数:  
//     s : 字符串首地址
// 返回值: 字符串 s 的长度, size_t 为 unsigned int 类型
// 
//   char str[] = "abc\0defg";
//    int n = strlen(str);
//    printf("n = %d\n", n);
//
//  5.54    强化训练:字符串追加
//#include <stdio.h>
//
//int main()
//{
//    char str1[] = "abcdef";
//    char str2[] = "123456";
//    char dst[100];
//
//    int i = 0;
//    while (str[i] != 0)
//    {
//
//    }
//}
///
// ---------------------------------------------------------------------------------------------下面的程序不对以后在看
///#define _CRT_SECURE_NO_WARNINGS
//#include <stdio.h>
//#include <string.h> 
//#include <stdlib.h>
//#include <math.h>
//#include <time.h>
//  gets
//int main(void)
//{
//    char str[100];
//
//    printf("获取的字符串为: %s\n", gets(str));
//
//    system("panse");
//    return EXIT_SUCCESS;
//}
// ---------------------------------------------------------------------------------------------下面的程序不对以后在看
//#define _CRT_SECURE_NO_WARNINGS
//#include <stdio.h>
//#include <string.h> 
//#include <stdlib.h>
//#include <math.h>
//#include <time.h>
 gets
//int main(void)
//{
//    char str[10];
//int ret = gets(str);
//   // printf("获取的字符串为: %s\n", fgets(str, sizeof(str),stdin));
//printf("ret = %d\n", ret);
//    system("panse");
//    return EXIT_SUCCESS;
//}

//#define _CRT_SECURE_NO_WARNINGS
//#include <stdio.h>
//#include <string.h> 
//#include <stdlib.h>
//#include <math.h>
//#include <time.h>
 puts
//int main(void)
//{
//   
//    char str[] = "hello world\n";
//
//    int ret = puts(str);     // pust("hello world");
//
//   
//    printf("ret = %d\n", ret);
//
//    system("panse");
//    return EXIT_SUCCESS;
//}

//  fputs
//#define _CRT_SECURE_NO_WARNINGS
//#include <stdio.h>
//#include <string.h> 
//#include <stdlib.h>
//#include <math.h>
//#include <time.h>
//
//int main(void)
//{
//    char str[] = "hello world";
//    int ret = fputs(str, stdout);   // puts ("hello world");
//
//    printf("ret = %d\n", ret);
//
//    system("panse");
//    return EXIT_SUCCESS;
//}

 fputs
//#define _CRT_SECURE_NO_WARNINGS
//#include <stdio.h>
//#include <string.h> 
//#include <stdlib.h>
//#include <math.h>
//#include <time.h>
//
//int main(void)
//{
//    char str[] = "hello world\n";
//    int ret = fputs(str, stdout);   // puts ("hello world");
//
//    printf("ret = %d\n", ret);
//
//    system("panse");
//    return EXIT_SUCCESS;
//}

 strlen () 函数 : 获取字符串的 有效长度: 不包含 \0
//#define _CRT_SECURE_NO_WARNINGS
//#include <stdio.h>
//#include <string.h> 
//#include <stdlib.h>
//#include <math.h>
//#include <time.h>
//
//int main(void)
//{
//    char str[] = "hello world";
//
//    printf("sizeof(str) = %u\n", sizeof(str));
//
//    printf("sizeof(str) = %u\n", strlen(str));
//
//    system("panse");
//    return EXIT_SUCCESS;
//}

 strlen () 函数 : 获取字符串的 有效长度: 不包含 \0
//#define _CRT_SECURE_NO_WARNINGS
//#include <stdio.h>
//#include <string.h> 
//#include <stdlib.h>
//#include <math.h>
//#include <time.h>
//
//int main(void)
//{
//    char str[] = "hello\0world";
//
//    printf("sizeof(str) = %u\n", sizeof(str));
//
//    printf("sizeof(str) = %u\n", strlen(str));
//
//    system("panse");
//    return EXIT_SUCCESS;
//}

实现 strlen () 函数 : 
//#define _CRT_SECURE_NO_WARNINGS
//#include <stdio.h>
//#include <string.h> 
//#include <stdlib.h>
//#include <math.h>
//#include <time.h>
//
//int main(void)
//{
//    char str[] = "hello world";
//
//    int i = 0;
//    while (str[i] != '\0')
//    {
//        i++;
//    }
//    printf("%d\n", i);
//
//    system("panse");
//    return EXIT_SUCCESS;
//}
//


//#define _CRT_SECURE_NO_WARNINGS
//#include <stdio.h>
//#include <string.h> 
//#include <stdlib.h>
//#include <math.h>
//#include <time.h>
//
//int main(void)
//{
//    char str1[] = "hello";
//    char str2[] = "world";
//
//    char str3[100] = { 0 };
//
//    int i = 0;
//    while (str1[i] != '\0')
//    {
//        str3[i] = str1[i];  //循环着将str1 中的每一个元素,交给str3
//        i++;
//    }   // str3 = [h e l l o]
//    printf("%d\n", i);    ==> 5
//
//    system("panse");
//    return EXIT_SUCCESS;
//}

//#define _CRT_SECURE_NO_WARNINGS
//#include <stdio.h>
//#include <string.h> 
//#include <stdlib.h>
//#include <math.h>
//#include <time.h>
//
//int main(void)
//{
//    char str1[] = "hello";
//    char str2[] = "world";
//
//    char str3[100] = { 0 };
//
//    int i = 0;
//    while (str1[i] != '\0')
//    {
//        str3[i] = str1[i];  //循环着将str1 中的每一个元素,交给str3
//        i++;
//    }   // str3 = [h e l l o]
//   // printf("%d\n", i);
//
//    int j = 0;    //  循环 str2
//
//    while (str2[j]) // 等价于 while(str2[j] !='\0') 等价于 while (str2[j] != 0)
//    {
//        str3[i + j] = str2[j];
//        j++;
//    }          //  str3 = [h e l l o w o r l d]
//    //   手动添加 \0 字符串结束标记
//    //  str3[i + j ] = '\0';
//    printf("str3 = %s\n", str3);
//    system("panse");
//    return EXIT_SUCCESS;
//}

//#define _CRT_SECURE_NO_WARNINGS
//#include <stdio.h>
//#include <string.h> 
//#include <stdlib.h>
//#include <math.h>
//#include <time.h>
//
//int main(void)
//{
//    char str1[] = "hello";
//    char str2[] = "world";
//
//    char str3[100];
//
//    int i = 0;
//    while (str1[i] != '\0')
//    {
//        str3[i] = str1[i];  //循环着将str1 中的每一个元素,交给str3
//        i++;
//    }   // str3 = [h e l l o]
//   // printf("%d\n", i);
//
//    int j = 0;    //  循环 str2
//
//    while (str2[j]) // 等价于 while(str2[j] !='\0') 等价于 while (str2[j] != 0)
//    {
//        str3[i + j] = str2[j];
//        j++;
//    }          //  str3 = [h e l l o w o r l d]
//    //   手动添加 \0 字符串结束标记
//    //  str3[i + j ] = '\0';
//    printf("%s\n", str3);
//    system("panse");
//    return EXIT_SUCCESS;
//}
//

//#define _CRT_SECURE_NO_WARNINGS
//#include <stdio.h>
//#include <string.h> 
//#include <stdlib.h>
//#include <math.h>
//#include <time.h>
//
//int main(void)
//{
//    int arr[] = { 54, 5, 16, 34, 6, 9, 34, 1, 7, 93 };
//
//    int i, j, temp;
//
//    for (i = 0; i < 10 - 1; i++)
//        for (j = 0; j < 10 - 1 -i; j++)
//            if (arr[j] < arr[j + 1])
//            {
//                temp = arr[j];
//                arr[j] = arr[j + 1];
//                arr[j + 1] = temp;
//            }
//  
//    for (size_t i = 0; i < 10; i++)
//    {
//        printf("%d ", arr[i]);
//    }
//    system("panse");
//    return EXIT_SUCCESS;
//}


//#define _CRT_SECURE_NO_WARNINGS
//#include <stdio.h>
//#include <string.h> 
//#include <stdlib.h>
//#include <math.h>
//#include <time.h>
//
//void bobble_sort(int arr[])  // 返回值 函数名  参数
//{
//    int i, j, temp;
//
//    for (i = 0; i < 10 - 1; i++)
//    {
//        for (j = 0; j < 10 - 1 - i; j++)
//        {
//            if (arr[j] < arr[j + 1])
//            {
//                temp = arr[j];
//                arr[j] = arr[j + 1];
//                arr[j + 1] = temp;
//            }
//        }
//    }
//}
//
//int main(void)
//{
//    int arr[] = { 54, 5, 16, 34, 6, 9, 34, 1, 7, 93 };
//
//    int i, j, temp;
//
//    for (i = 0; i < 10 - 1; i++)
//    {
//        for (j = 0; j < 10 - 1 - i; j++)
//        {
//            if (arr[j] < arr[j + 1])
//            {
//                temp = arr[j];
//                arr[j] = arr[j + 1];
//                arr[j + 1] = temp;
//            }
//        }
//    }
//    for (size_t i = 0; i < 10; i++)
//    {
//        printf("%d ", arr[i]);
//    }
//    system("panse");
//    return EXIT_SUCCESS;
//}


//函数的作用:
//     1,提高代码的复用率
//     2.提高程序模块化组织性

//  函数分类:
//    系统库函数: 标准C库, libc
//       1,引入头文件 ---  声明函数
//       2,根据函数原型调用
//   用户自定义;

//随机数:
//   1、播种随机数种子: srand(time(NULL));
//   2、引入头文件 #include <stdio.h> <time.h>
//   3、生成随机数: rand() % 100;

//  函数定义:
//        包含 函数原型(返回值类型、函数名、形参列表) 和 函数体(大括号一对,具体代码实现)
//    形参列表:形式参数列表。一定包含类型名 形参名。
//    int add(int a, int b, int c)
//   {
//          return a+b+c;
//   }
//   int test(char ch, short b, int arr[],)
//  函数调用:
//        包含 函数名(实参列表);
//       int ret = add(10, 4, 28);
//        实参(实际参数):在调用是,传参必须严格按照形参填充,(参数的个数、类型、顺序)没有类型描述符,
//          int arr[] = {1, 3, 6};
// 
//  函数声明:
//        包含 函数原型(返回值类型、函数名、形参列表)  +  ";"
//        要求 在函数调用之前,编译必须见过函数定义,否则,需要函数声明。
// 
//      隐式声明:
//          默认编译器做隐式声明函数时,返回都为 int 根据调用语句补全函数名和形参列表
//     #include<xxx.h>  ==> 包含函数的声明
// 
//  exit函数:
//      return: 
//               返回当前函数调用,将返回值返回给调用这
//     exit() 函数:
//            退出当前程序
// 
//  多文件编程:
//   防止头文件重复包含:

--------------------------------------------------------------下面的程序不对以后在看
//#define _CRT_SECURE_NO_WARNINGS
//#include <stdio.h>
//#include <string.h> 
//#include <stdlib.h>
//#include <math.h>
//#include <time.h>
//
//void bobble_sort(int arr[])  // 返回值 函数名  参数
//{
//    int i, j, temp;
//
//    for (i = 0; i < 10 - 1; i++)
//    {
//        for (j = 0; j < 10 - 1 - i; j++)
//        {
//            if (arr[j] < arr[j + 1])
//            {
//                temp = arr[j];
//                arr[j] = arr[j + 1];
//                arr[j + 1] = temp;
//            }
//        }
//    }
//}
//
//void print_arr(int arr[])
//{
//    for (size_t i = 0; i < 10; i++)
//    {
//        printf("%d ", arr[i]);
//    }
//}
//int main(void)
//{
//    int arr[] = { 54, 5, 16, 34, 6, 9, 34, 1, 7, 93 };
//
//    bubble_sort(arr);
//
//    print_arr(arr);
//
//    system("panse");
//    return EXIT_SUCCESS;          //  低层 调用 _exit(); 做退出
//}


//--------------------------------------------------------------下面的程序不对以后在看
//#define _CRT_SECURE_NO_WARNINGS
//#include <stdio.h>
//#include <string.h> 
//#include <stdlib.h>
//#include <math.h>
//#include <time.h>
//
//void bobble_sort(int arr[])  // 返回值 函数名  参数
//{
//    int i, j, temp;
//
//    for (i = 0; i < 10 - 1; i++)
//    {
//        for (j = 0; j < 10 - 1 - i; j++)
//        {
//            if (arr[j] < arr[j + 1])
//            {
//                temp = arr[j];
//                arr[j] = arr[j + 1];
//                arr[j + 1] = temp;
//            }
//        }
//    }
//}
// 
//
//void print_arr(int arr[])
//{
//    for (size_t i = 0; i < 10; i++)
//    {
//        printf("%d ", arr[i]);
//    }
//}
//
//void bubble_sort(int arr[]);   // 函数声明
//int add(int, int);
//
//int add(int a, int b)
//{
//    return a + b;
//}
//int main(void)
//{
//    printf("add = %d\n", add(2, 6));
//    int arr[] = { 54, 5, 16, 34, 6, 9, 34, 1, 7, 93 };
//
//    bubble_sort(arr);
//
//    print_arr(arr);
//
//    system("panse");
//    return EXIT_SUCCESS;
//}

//#define _CRT_SECURE_NO_WARNINGS
//#include <stdio.h>
//#include <string.h> 
//#include <stdlib.h>
//#include <math.h>
//#include <time.h>
//
//int func(int a, char ch);
//int main(void)
//{
//    int ret = func(10, 'a');
//
//    printf("ret = %d\n", ret);
//
//    system("panse");
//    return EXIT_SUCCESS;
//}
//
//int func(int a, char ch)
//{
//    printf("a = %d\n", a);
//
//    printf("ch = %c\n", ch);
//
//    return 10;
//}

//#define _CRT_SECURE_NO_WARNINGS
//#include <stdio.h>
//#include <string.h> 
//#include <stdlib.h>
//#include <math.h>
//#include <time.h>
//
//int func(int a, char ch);
//int main(void)
//{
//    int ret = func(10, 'a');
//
//    printf("ret = %d\n", ret);
//
//    system("panse");
//    return EXIT_SUCCESS;
//}
//
//int func(int a, char ch)
//{
//    printf("a = %d\n", a);
//
//    printf("ch = %c\n", ch);
//
//    exit(1);
//}
//
//#define _CRT_SECURE_NO_WARNINGS
//#include <stdio.h>
//#include <string.h> 
//#include <stdlib.h>
//#include <math.h>
//#include <time.h>
//
//int func(int a, char ch);
//int main(void)
//{
//    int ret = func(10, 'a');
//
//    printf("ret = %d\n", ret);
//
//    system("panse");
//    // return EXIT_SUCCESS;
//    exit(EXIT_SUCCESS);
//}
//int func(int a, char ch)
//{
//    printf("a = %d\n", a);
//
//    printf("ch = %c\n", ch);
//
//    return 10;
//}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值