C
tianyingang
感谢关注
展开
-
char*加上一个整数会发生什么?
a指向一个字符串"hello", "hello"代表这个字符串的起始地址,那么,"hello" + 1就代表这个字符串的第二个字符所在的地址。因此b相当于在a的基础上向后移了一位,因此b指向的字符串为"ello",此时a和b会指向同一个字符串的不同位置吗?不过通过这个例子可以说明给字符串加上整数会发生什么。原创 2023-09-27 09:16:45 · 229 阅读 · 0 评论 -
排序
void shellSort(int array[], int n) { // Rearrange elements at each n/2, n/4, n/8, ... intervals for (int interval = n / 2; interval > 0; interval /= 2) { for (int i = interval; i < n; i += 1) { int temp = array[i]; int j; f.原创 2021-05-27 15:19:24 · 69 阅读 · 0 评论 -
ssize_t 和 size_t
#ifndef __SIZE_TYPE__#define __SIZE_TYPE__ long unsigned int#endif#if !(defined (__GNUG__) && defined (size_t))typedef __SIZE_TYPE__ size_t;//size_t是无符号长整形# define __STD_TYPE t...原创 2020-04-20 11:13:01 · 172 阅读 · 0 评论 -
使用管道在两个相关进程之间传输数据
intmain(int argc,char **argv){ pid_t pidChild; int pip[2]; pipe(pip); pidChild = fork(); switch(pidChild){ case -1: exit(-1); case 0:{//child ...原创 2020-04-07 21:09:50 · 405 阅读 · 0 评论 -
打印文件类型
#include <stdlib.h>#include <fcntl.h>#include <sys/stat.h>char * printFileType(const char *filename, struct stat *buf){ int fd = open("/home/zhihui/Music",O_RDONLY); fst...原创 2020-04-07 20:24:08 · 312 阅读 · 0 评论 -
strlen和sizeof()的区别
strlen 计算不包含终止 null 字节的字符串长度,而 sizeof 则计算包括终止 null字节的缓冲区长度。两者之间的另一个差别是,使用 strlen 需进行一次函数调用,而对于sizeof 而言,因为缓冲区已用已知字符串进行初始化,其长度是固定的,所以 sizeof 是在编译时计算缓冲区长度。...原创 2020-03-13 15:23:03 · 98 阅读 · 0 评论 -
APUE学习笔记:10.15 函数sigsetjmp和siglongjmp
输出 $ ./ctest &[1] 7432starting main: SIGQUIT$ kill -USR1 7432starting sig_usr1: SIGQUIT SIGUSR1$ in sig_alrm: SIGQUIT SIGUSR1 SIGALRMfinishing sig_usr1: SIGQUIT SIGUSR1ending main:...原创 2020-01-18 17:02:45 · 93 阅读 · 0 评论 -
apue自学笔记14.3 记录锁.fcntl记录锁
函数原型如下:#include<fcntl.h>int fcntl(int fd,int cmd,.../* struct flock *flockptr */); //返回值:若成功,依赖于cmd,否则,返回-1//cmd 取下面三个值之一# define F_GETLK 5 /* Get record locking inf...原创 2020-01-01 14:35:22 · 162 阅读 · 0 评论 -
关于setpgid函数的小知识点
我想在主进程里面调用setpgid()来将第一个子进程的进程组ID设置为第二个进程的进程ID,想知道这样会不会自动创建一个新的进程组,第二个子进程作为进程组组长。代码如下#include <stdio.h>#include <stdlib.h>#include <zconf.h>int main() { pid_t pid1,pid...原创 2019-12-27 01:10:02 · 1811 阅读 · 0 评论 -
Linux_unix系统编程手册30.2.4
运行Linux_unix系统编程手册30.2.4代码程序清单30-4发现输出与书中给出的不符。源代码如下:预期输出为:我的代码除了打印输出没有使用errExitEN函数以外,其他都和示例程序一致。如下:#include <stdlib.h>#include <stdio.h>#include <pthread.h>...原创 2020-01-18 17:03:53 · 177 阅读 · 0 评论 -
c语言round函数使用问题
round 是实现四舍五入的函数,但我在使用的时候遇到点问题,编译器一直报错undefined reference to `round'半天都找不到原因,终于搞清楚了,记在这里,供遇到相同问题的朋友参考。首先给出函数原型double round( double x);float round( float x); // C++ onlylong double ro...原创 2019-11-25 12:08:15 · 8898 阅读 · 0 评论 -
linux alarm函数
#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <string.h>#include <signal.h>void sig_handler(int signo){ char * sd = strsignal(signo); p...原创 2019-11-15 11:52:50 · 123 阅读 · 0 评论 -
linux errno值
#ifndef _ASM_GENERIC_ERRNO_H#define _ASM_GENERIC_ERRNO_H#include <asm-generic/errno-base.h>#define EDEADLK 35 /* Resource deadlock would occur */#define ENAMETOOLONG 36 /* File name too ...原创 2019-11-11 11:01:37 · 488 阅读 · 0 评论 -
对非特权用户来讲setuid 和 setgid 有什么用
#include <unistd.h>int setuid(uid_t uid);int setgid(gid_t gid);对特权用户来讲setuid 将进程的实际用户ID,有效用户ID,保存的设置用户ID全都设置为 uidsetgid 将进程的实际组ID,有效组ID,保存的设置组ID全都设置为 uid这个很好理解。对非特权用户来讲当uid等于实际用户...原创 2019-11-11 10:43:02 · 232 阅读 · 0 评论 -
fork创建一个进程
#include <stdio.h>#include <unistd.h>void son_process_handler(void);void parent_process_handler(void);int main(int argc,char ** argv) { pid_t pid; pid = fork(); if(pid == 0...原创 2019-11-06 22:19:26 · 181 阅读 · 0 评论 -
getpid getppid getuid geteuid getgid getegid函数使用
#include <stdio.h>#include <unistd.h>int main(int argc,char ** argv) { pid_t pid_tmp; pid_tmp = getpid(); printf("the ID of the process is : %d\n",pid_tmp); pid_tmp = getp...原创 2019-11-06 22:04:50 · 362 阅读 · 0 评论 -
多线程例程
#include <stdio.h>#include <stdlib.h>#include <pthread.h>#include <stdbool.h>#include <zconf.h>bool flag = true;void * thread_handler1(void * para){ while(fla...原创 2019-11-06 18:08:01 · 122 阅读 · 0 评论 -
getenv函数
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <shadow.h>#include <grp.h>intmain(int argc,char **argv){ if(argc != 2){ printf("usag...原创 2019-11-06 11:07:55 · 298 阅读 · 0 评论 -
strftime 函数
#include <stdio.h>#include <time.h>int main(int argc,char ** argv) { time_t time1; time(&time1); struct tm tm1; tm1 = *(localtime(&time1)); char buf[1000];...原创 2019-11-05 23:51:24 · 317 阅读 · 0 评论 -
time函数 localtime函数获取当前时间
#include <stdio.h>#include <time.h>int main(int argc,char ** argv) { time_t time1; time(&time1); struct tm tm1; tm1 = *(localtime(&time1)); printf("%d-",tm...原创 2019-11-05 23:26:18 · 1113 阅读 · 0 评论 -
基本数据类型
/* Structure of the password file. */struct spwd { char *sp_namp; /* Login name. */ char *sp_pwdp; /* Encrypted password. */ long int sp_lstchg; /* Date of last change. */ l...原创 2019-11-05 18:08:10 · 136 阅读 · 0 评论 -
getpwent函数
#include <stdio.h>#include <pwd.h>intmain(){ struct passwd * pw_Ptr ; while((pw_Ptr = getpwent()) != NULL){ printf("%s:",pw_Ptr->pw_name); printf("%s:",pw_...原创 2019-11-05 17:00:32 · 419 阅读 · 0 评论 -
Linux 获取/etc/passwd函数getpwuid getpwnam
#include <stdio.h>#include <pwd.h>intmain(){ struct passwd * pw_Ptr ; pw_Ptr = getpwuid(1000); //pw_Ptr = getpwnam("zhihui"); if(pw_Ptr == NULL){ printf("...原创 2019-11-05 16:51:56 · 334 阅读 · 0 评论 -
段错误
原创 2019-11-05 11:31:26 · 148 阅读 · 0 评论 -
创建临时文件mkstemp函数和 tmpfile函数
#include <stdio.h>#include "apue.h"#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>#include <sys/time.h>int main() { char name[L_tmpnam] = {"/tmp/fi...原创 2019-11-05 11:21:05 · 541 阅读 · 0 评论 -
修改文件时间信息的函数futimens、utimensat和utimes
#include <sys/stat.h>int futimens(int fd, const struct timespec times[2]);int utimensat(int fd, const char *path, const struct timespec times[2], int flag);两个函数返回值:若成功,返回0;若出错,返回-1(1)如果t...原创 2019-11-01 11:23:15 · 1221 阅读 · 0 评论 -
秦pro
/***************************************************************************** Copyright (c) 2018, 比亚迪汽车 All rights reserved. 文件名称: idriving_api.h 摘 要: API接口的定义 其他: 函数列表: 当前版本: 1....原创 2019-10-16 14:17:00 · 221 阅读 · 0 评论 -
CMake笔记
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)project(recipe-04 LANGUAGES CXX)add_library(message-objs OBJECT Message.cpp Message.hpp)set_target_properties(message-objs PROPERTIES POSITI...原创 2019-07-02 19:06:10 · 171 阅读 · 0 评论 -
判断回文数
#include<stdio.h>#include<string.h>bool isPalindrome(char *s){ size_t length; char *p1, *p2; char c1, c2; length = strlen(s); p1 = s; c1 = *p1; p2 = p1 + length - 1 ; c2 = *p2;...原创 2019-04-30 15:46:23 · 133 阅读 · 0 评论 -
猴子吃桃问题
猴子吃桃问题:猴子第一天摘下若干个桃子,当即吃了一半,还不过瘾,又多吃了一个。第二天早上又将第一天剩下的桃子吃掉一半,有多吃了一个。以后每天早上都吃了前一天剩下的一半零一个。到第 10 天早上想再吃时,发现只剩下一个桃子了。编写程序求猴子第一天摘了多少个桃子。#include<stdio.h>int peachRemain(int day){ int peach; if ...原创 2019-04-30 10:30:59 · 90 阅读 · 0 评论 -
算法学习笔记之插入排序算法
#include <stdio.h>int main(void){ int a[10] = { 11,2,32,25,90,8,16,56,44,7 }; int key, i, j, k; for (j = 1; j < 10; j++) { i = j - 1; key = a[j]; w...原创 2019-04-19 00:09:42 · 71 阅读 · 0 评论 -
求平方根,路径文件名,路径文件夹名
unsigned short int_sqrt(unsigned long a){ unsigned long rem = 0; unsigned long root_val = 0; unsigned long divisor = 0; int i; for(i=0; i<16; ++i) { root_val <&...原创 2019-04-23 10:47:55 · 90 阅读 · 0 评论 -
CMake生成的动态库和静态库名称一致
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)project(recipe-04 LANGUAGES CXX)add_library(message-objs OBJECT Message.cpp Message.hpp)set_target_properties(message-objs...原创 2019-07-02 19:10:01 · 1109 阅读 · 0 评论 -
分治法排序
#include <stdio.h>#include <stdlib.h>int merge(int * objary,unsigned int index_start,unsigned int index_middle,unsigned int index_end){ int n1 = index_middle - index_start + 1;...原创 2019-06-24 15:26:12 · 110 阅读 · 0 评论 -
clion帮助文档
https://www.jetbrains.com/help/clion/2018.1/clion-quick-start-guide.html#d19869e38https://www.jetbrains.com/help/clion/2018.1/working-with-cmake.html原创 2019-06-24 16:22:20 · 1210 阅读 · 0 评论 -
n位二进制数相加
#include <stdio.h>#include <stdbool.h>#define ARRAY_SIZE 64bool add_Two_Bin_Number(int * array1,int * array2,int * array3){ int carry_in_flag = 0; int tmp; __int64_t i; ...原创 2019-07-10 16:31:37 · 443 阅读 · 0 评论 -
选择排序算法
#include <stdio.h>int get_min_of_array(int * array ,unsigned int index_start,unsigned int index_end){ int min = array[index_start]; int min_index = 0; for(int i = index_start; i ...原创 2019-07-24 18:43:00 · 65 阅读 · 0 评论 -
给定的数是否为数组两元素之和
//给定n个整数的集合S和另一个整数x,该算法能确定是否存在两个数之和等于x#include <stdio.h>#include <stdbool.h>#include <malloc.h>int merge(int * objary,unsigned int index_start,unsigned int index_middle,unsigne...原创 2019-07-25 16:12:26 · 246 阅读 · 0 评论 -
另一种检查数组中是否有两元素之和等于给定数
//给定n个整数的集合S和另一个整数x,该算法能确定S中是否存在两个数其和刚好为x#include <stdio.h>#include <stdbool.h>#include <malloc.h>int merge(int * objary,unsigned int index_start,unsigned int index_middle,un...原创 2019-07-25 16:20:36 · 333 阅读 · 0 评论 -
test
[code=c]#include<stdio.h>int main(void){printf("hello world.\n");return 0;}[/code]原创 2019-09-11 17:58:50 · 89 阅读 · 0 评论