栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

2022.3.27

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

2022.3.27

//  2022.3.27字符串的输入输出
//  由于字符串采用了'n'标志,字符串的输入输出将变得简单方便
//#include
//
//int main()
//{
//    char str[100];
//
//    printf(input string : n);
//    scanf("%s, str"); //scanf("%s",str) 默认以空格分离
//    printf("output:%sn", str);
//
//    return 0;
//}
//
//1、gets()
//#include
//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 = %sn", str);
//
// (2) fgets()
//#include
//char* fgets(char* s, int size, FILE* stream);
//  功能: 从stream 指定的文件内读入字符,保存到s所指定的内存空间,直到出现换行字符,
//         读到文件结尾或是已读了 size-1 个字符为止,最后会自动加上字符""作为字符串结束
//      参数 :
//      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("hellon"); /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
// size_t strlen(const char *s);
//  功能: 计算指定指定字符串 s 的长度,不包含字符串结束符''.
// 参数:  
//     s : 字符串首地址
// 返回值: 字符串 s 的长度, size_t 为 unsigned int 类型
// 
//   char str[] = "abcdefg";
//    int n = strlen(str);
//    printf("n = %dn", n);
//
//  5.54    强化训练:字符串追加
//#include
//
//int main()
//{
//    char str1[] = "abcdef";
//    char str2[] = "123456";
//    char dst[100];
//
//    int i = 0;
//    while (str[i] != 0)
//    {
//
//    }
//}
///
// ---------------------------------------------------------------------------------------------下面的程序不对以后在看
///#define _CRT_SECURE_NO_WARNINGS
//#include
//#include  
//#include
//#include
//#include
//  gets
//int main(void)
//{
//    char str[100];
//
//    printf("获取的字符串为: %sn", gets(str));
//
//    system("panse");
//    return EXIT_SUCCESS;
//}
// ---------------------------------------------------------------------------------------------下面的程序不对以后在看
//#define _CRT_SECURE_NO_WARNINGS
//#include
//#include  
//#include
//#include
//#include
 gets
//int main(void)
//{
//    char str[10];
//int ret = gets(str);
//   // printf("获取的字符串为: %sn", fgets(str, sizeof(str),stdin));
//printf("ret = %dn", ret);
//    system("panse");
//    return EXIT_SUCCESS;
//}

//#define _CRT_SECURE_NO_WARNINGS
//#include
//#include  
//#include
//#include
//#include
 puts
//int main(void)
//{
//   
//    char str[] = "hello worldn";
//
//    int ret = puts(str);     // pust("hello world");
//
//   
//    printf("ret = %dn", ret);
//
//    system("panse");
//    return EXIT_SUCCESS;
//}

//  fputs
//#define _CRT_SECURE_NO_WARNINGS
//#include
//#include  
//#include
//#include
//#include
//
//int main(void)
//{
//    char str[] = "hello world";
//    int ret = fputs(str, stdout);   // puts ("hello world");
//
//    printf("ret = %dn", ret);
//
//    system("panse");
//    return EXIT_SUCCESS;
//}

 fputs
//#define _CRT_SECURE_NO_WARNINGS
//#include
//#include  
//#include
//#include
//#include
//
//int main(void)
//{
//    char str[] = "hello worldn";
//    int ret = fputs(str, stdout);   // puts ("hello world");
//
//    printf("ret = %dn", ret);
//
//    system("panse");
//    return EXIT_SUCCESS;
//}

 strlen () 函数 : 获取字符串的 有效长度: 不包含
//#define _CRT_SECURE_NO_WARNINGS
//#include
//#include  
//#include
//#include
//#include
//
//int main(void)
//{
//    char str[] = "hello world";
//
//    printf("sizeof(str) = %un", sizeof(str));
//
//    printf("sizeof(str) = %un", strlen(str));
//
//    system("panse");
//    return EXIT_SUCCESS;
//}

 strlen () 函数 : 获取字符串的 有效长度: 不包含
//#define _CRT_SECURE_NO_WARNINGS
//#include
//#include  
//#include
//#include
//#include
//
//int main(void)
//{
//    char str[] = "helloworld";
//
//    printf("sizeof(str) = %un", sizeof(str));
//
//    printf("sizeof(str) = %un", strlen(str));
//
//    system("panse");
//    return EXIT_SUCCESS;
//}

实现 strlen () 函数 : 
//#define _CRT_SECURE_NO_WARNINGS
//#include
//#include  
//#include
//#include
//#include
//
//int main(void)
//{
//    char str[] = "hello world";
//
//    int i = 0;
//    while (str[i] != '')
//    {
//        i++;
//    }
//    printf("%dn", i);
//
//    system("panse");
//    return EXIT_SUCCESS;
//}
//


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

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

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

//#define _CRT_SECURE_NO_WARNINGS
//#include
//#include  
//#include
//#include
//#include
//
//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
//#include  
//#include
//#include
//#include
//
//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
//   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  ==> 包含函数的声明
// 
//  exit函数:
//      return: 
//               返回当前函数调用,将返回值返回给调用这
//     exit() 函数:
//            退出当前程序
// 
//  多文件编程:
//   防止头文件重复包含:

--------------------------------------------------------------下面的程序不对以后在看
//#define _CRT_SECURE_NO_WARNINGS
//#include
//#include  
//#include
//#include
//#include
//
//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
//#include  
//#include
//#include
//#include
//
//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 = %dn", 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
//#include  
//#include
//#include
//#include
//
//int func(int a, char ch);
//int main(void)
//{
//    int ret = func(10, 'a');
//
//    printf("ret = %dn", ret);
//
//    system("panse");
//    return EXIT_SUCCESS;
//}
//
//int func(int a, char ch)
//{
//    printf("a = %dn", a);
//
//    printf("ch = %cn", ch);
//
//    return 10;
//}

//#define _CRT_SECURE_NO_WARNINGS
//#include
//#include  
//#include
//#include
//#include
//
//int func(int a, char ch);
//int main(void)
//{
//    int ret = func(10, 'a');
//
//    printf("ret = %dn", ret);
//
//    system("panse");
//    return EXIT_SUCCESS;
//}
//
//int func(int a, char ch)
//{
//    printf("a = %dn", a);
//
//    printf("ch = %cn", ch);
//
//    exit(1);
//}
//
//#define _CRT_SECURE_NO_WARNINGS
//#include
//#include  
//#include
//#include
//#include
//
//int func(int a, char ch);
//int main(void)
//{
//    int ret = func(10, 'a');
//
//    printf("ret = %dn", ret);
//
//    system("panse");
//    // return EXIT_SUCCESS;
//    exit(EXIT_SUCCESS);
//}
//int func(int a, char ch)
//{
//    printf("a = %dn", a);
//
//    printf("ch = %cn", ch);
//
//    return 10;
//}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/784742.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号