随笔分类 - C学习
摘要:This chapter describes buffering modes used by z/OS XL C/C++ library functions available to control buffering and methods of flushing buffers.z/OS XL C/C++ uses buffers to map C I/O to system-level I/O. When z/OS XL C/C++ performs I/O operations, it uses one of the following buffering modes:Line buf
阅读全文
摘要:今天看APUE上一道题,要求不能用fcnt1来替换dup1.刚开始的思路是dup一个,测试发现与期望的不一致就马上关闭,发现遇到无限循环,刚才想了下,才发现一旦close掉,再次dup仍然是分配最小的fd,所以永远也得不到最终的结果。囧!好吧,依据网友的,自己整理了下:#include #include #include #include #include #include #include #include #include #include #define err_sys(info) ...
阅读全文
摘要:转自http://www.slyar.com/blog/prim-simplicity-c.html#include <stdio.h>#include <stdlib.h>#define MAX 100#define MAXCOST 0x7fffffffint graph[MAX][MAX];int Prim(int graph[][MAX], int n){ /* lowcost[i]记录以i为终点的边的最小权值,当lowcost[i]=0时表示终点i加入生成树 */ int lowcost[MAX]; /* mst[i]记录对应lowcost[i]的起点,当mst
阅读全文
摘要:今天上午跟同学们一起去了市区一个酒店参加华赛的面试,11点才到,去乡村基吃了饭,回来一直等到2点多,才被通知要面试。面试官首先让我自己介绍下,这是次要的,后面的面试题才是重点,全是C的,而且要我做三份,5分钟搞定,我一下子懵了,悲剧了,各种C语言的细节,伤不起啊,最后面试官和蔼地说:咱们一起看下。他给我讲解了每道题,我当时真叫个尴尬啊,看来要想做软件研发得慎重啊,要补好细节!特别是C,光知道C++貌似没什么用!
阅读全文
摘要:大数相加,转的算法很明显:#include <stdio.h>#include <string.h> char a[105],b[105]; char* add(char *a,char *b){ int i,j,k = 0,tmp[105],l1 = strlen(a),l2 = strlen(b); for (i = l1-1,j = l2-1;i >= 0 && j >= 0;--i,--j) tmp[k++] = a[i]+b[j]-'0'-'0'; for (;i >= 0;--i) tmp[k
阅读全文
摘要:罗列你知道的排序算法,并注明他们的复杂度冒泡排序法 复杂度是O(n2)选择排序负 复杂度是O(n2)插入排序法 复杂度是O(n2)合并排序法 复杂度是O(nlgn)快速排序法 复杂度是O(nlgn)合并排序法 复杂度是O(nlgn)Shell排序法 复杂度是O(nlgn)
阅读全文
摘要:参考网上的代码,谁知道有问题,修改了下,貌似可以了,VS2008上试验毫无鸭梨。#include <iostream>using namespace std;//计算长度size_t str_len(char *str_source){ size_t i = 0; while (*str_source++ != '\0') { ++i; } return i;}//翻转指定位置的字符串char *reverse_str(char *str_source,size_t str_begin,size_t str_end){ size_t len = str_len(st
阅读全文
摘要:总线:贯穿整个系统的电子管道,携带信息字节,并负责在各个部件间传递。主存:临时存储设备,在处理器执行程序时,用来存放程序和程序处理的数据。DRAM芯片组成。
阅读全文
摘要:代码贴上:#include <stdlib.h>#include <string.h>#include <time.h>#include <iostream>// using namespace std;int main(){ const char *c = "0123456789abcdefghijklmnopqrstuvwxyz"; srand(static_cast<unsigned int>(time(NULL))); std::cout << "The random char arr
阅读全文
摘要:测试字符串是否是回文字串 1. bool is_palindrome(char *str, int size) 2. { 3. int tmp1 = size-2, tmp2 = (size-1)/2; 4. for (int i = 0; i < tmp2; ++i) 5. { 6. if (str[i] != str[tmp1-i]) 7. return false; 8. } 9. return true; 10. } 然后,不管对应位置的大小写:可以这么写:# bool is_palindrome(char *str, int size) # { # int tmp1 = siz
阅读全文
摘要:代码一步步实现C库,O(∩_∩)O~!但是标准库的实现是这样的[代码]标准库的实现是基于正确、有效、安全基础上写的,从这个代码上可见一斑啊!VS2008内的实现是:[代码]
阅读全文
摘要:The assert header is used for debugging purposes.Macros: assert();External References: NDEBUG2.1.1 assertDeclaration: void assert(int expression);The assert macro allows diagnostic information to be written to the standard error file. If expression evaluates to 0 (false), then the expression, source
阅读全文
摘要:These preprocessing directives create conditional compiling parameters that control thecompiling of the source code. They must begin on a separate line.Syntax: #if constant_expression #else #endif or #if constant_expression #elif constant_expression #endifThe compiler only compiles the code after t
阅读全文
摘要:/* Copyright (C) 1999 Lucent Technologies *//* From 'Programming Pearls' by Jon Bentley *//* bitsort.c -- bitmap sort from Column 1 * Sort distinct integers in the range [0..N-1] */#include <stdio....
阅读全文