
C语言
cactus-kb
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
解决VS2017使用scanf报错的方法
(1)直接在代码最前面添加#define _CRT_SECURE_NO_WARNINGS 1(2)在创建的项目中修改属性(3)找到所安装的VS2017,在里面找到newc++file.cpp文件,例如我自己就是根据E:\vs2017\Common7\IDE\VC\vcprojectitems找到newc++file.cpp文件的,每个人的安装路径不一样,需要根据自己的安装路径进行寻找。然...原创 2019-08-03 23:33:14 · 1107 阅读 · 1 评论 -
三子棋代码
#ifndef _GAME_H_#define _GAME_H_#include<windows.h>#include<string.h>#include<stdio.h>#include<stdlib.h>#include<time.h>void InitBoard(char board[][3], int row, in...原创 2019-08-10 15:50:51 · 113 阅读 · 0 评论 -
四种方法求一个整数存储在内存中的二进制中1的个数
(1)int Num(int n) { int count = 0; while (n != 0) { if (n % 2 == 1) { count++; } n = n / 2; } return count;}int main() { printf("%d\n", Num(13)); system("pause"); return 0;}这个代码是...原创 2019-08-17 21:44:21 · 262 阅读 · 0 评论 -
代码实现判断当前机器是大端还是小端
大端(存储)模式,是指数据的低位保存在内存的高地址中,而数据的高位,保存在内存的低地址中;小端(存储)模式,是指数据的低位保存在内存的低地址中,而数据的高位,,保存在内存的高地址中。(1)#define _CRT_SECURE_NO_WARNINGS 1#include<stdio.h>#include<windows.h>int Fun() { int a ...原创 2019-08-17 22:53:29 · 697 阅读 · 0 评论 -
猜数字游戏代码
void Menu() { printf("--------- MENU ---------\n"); printf("********* 1.PLAY *********\n"); printf("********* 0.EXIT *********\n"); printf("--------------------------\n");}void Game() { int r...原创 2019-08-21 18:25:53 · 3735 阅读 · 0 评论 -
屏幕闪退
vs运行程序,界面出现闪退时,可加上如下代码段#include<windows.h>int main(){system(“pause”);return 0;}strlen:遇到’\0’停止计算;%s:遇到’\0’停止打印;sizeof(arr):求整个数组的字节大小;int len = sizeof(arr)/sizeof(arr[0]);...原创 2019-08-02 19:33:56 · 201 阅读 · 0 评论 -
C语言中动态内存分配
malloc:用于执行动态内存分配void *malloc(size_t size);//参数类型size_t是一个无符号类型malloc的参数就是需要分配的内存字节(字符)数,malloc所分配的是一块连续的内存,当操作系统无法向malloc提供更多的内存时,malloc就会返回一个NULL指针,因此对于malloc的返回值一定要做检查,确保它并非是NULL。free:用于执行动态内存的释...原创 2019-08-29 12:16:07 · 174 阅读 · 0 评论 -
C语言中strlen和sizeof
int main() { char arr[] = { 1,2,3,4,5,6,7,8,9,10 }; char arr1[] = "abcde"; char arr3[] = { 'a','b','c' }; printf("%d\n", strlen(arr));//(1)未定义行为 printf("%d\n", strlen(arr1));//(2)strlen求的是**字符串**...原创 2019-08-29 11:24:38 · 178 阅读 · 0 评论 -
字符指针
#define _CRT_SECURE_NO_WARNINGS 1#include<stdio.h>#include<windows.h>int main() { char str1[] = "hello world"; char str2[] = "hello world"; char *str3 = "hello world"; char *str4 = ...原创 2019-08-27 15:46:38 · 147 阅读 · 0 评论 -
数组名和&数组名的地址
#define _CRT_SECURE_NO_WARNINGS 1#include<stdio.h>#include<windows.h>int main() { int arr[10] = {1}; printf("%p\n", arr); printf("%p\n", &arr); printf("%p\n", arr + 1); printf(...原创 2019-08-27 15:28:38 · 210 阅读 · 0 评论