`
文章列表
接上一篇:C语言内存对齐详解(2) 在minix的stdarg.h文件中,定义了如下一个宏: /* Amount of space required in an argument list for an arg of type TYPE. * TYPE may alternatively be an expression whose type is used. */ #define __va_rounded_size(TYPE) \ (((sizeof (TYPE) + sizeof (int) - 1) / sizeof (int)) * sizeof (int) ...
接上一篇:C语言内存对齐详解(1)   VC对结构的存储的特殊处理确实提高CPU存储变量的速度,但是有时候也带来了一些麻烦,我们也屏蔽掉变量默认的对齐方式,自己可以设定变量的对齐方式。VC 中提供了#pragma pack(n)来设定 ...
一、数据类型:       在任何编程语言中,数据类型作为一个整体,ANSI-C包含的类型为:int、double、char……,程序员很少满意语言本身提供的数据类型,一个简单的办法就是构造类似:array、struct 或union。       那么,什么是数据类型呢?我们可以这样定义:一种数据类型是一些值的集合——通常char类型共有256不同的值,int有更多,double也包含更多的值,但是它通常和数学意义上的实数不同。       相应地,我们可以定义数据类型:包含一些值的集合,在值上面添加一些操作。通常,这些值都是计算机可以表示,同时对其的操作或多或少反应了可行的硬件指令 ...
一、什么是字节对齐,为什么要对齐?     现代计算机中内存空间都是按照byte划分的,从理论上讲似乎对任何类型的变量的访问可以从任何地址开始,但实际情况是在访问特定类型变量的时候经常在特定的内存地址访问,这就需 ...
在minix2.0源代码中,有相当经典的时间转换函数实现(src\ src\ lib\ ansi\ asctime.c),今天我们就来分析一下asctime.c中的源码 首先引入几个相关的头文件: 1、time.h 主要的结构体与相关定义: struct tm { int tm_sec; /* 分钟后面的秒[0, 59] */ int tm_min; /* 小时后面的分钟[0, 59] */ int tm_hour; /* 距离凌晨00:00点的小时数[0, 23] */ int tm_mday; /* 月中的某一天[1, 31] */ i ...
编写函数expand(s1,s2), 将字符串s1中类似于a-z一类的速记符号在字符串s2中扩展为等价的完整列表abc……xyz。该函数可以处理大小写字母和数字,并可以处理a-b-c、a-z0-9与a-z等类似的情况。作为前导和尾随的字符原样复制 #include<stdio.h> #include<ctype.h> #include<string.h> int judge(char a, char b) //判断'-'两端的字符是否符合速记符号扩展的要求 { if(isdigit(a) && isdigit(b)) ...
编写一个函数escape(s,t),将字符串t复制到字符串s中,并在复制的过程中将换行符、制表符等不可见字符分别转换为\n 、\t等相应的可见的转义字符序列。要求是用switch语句。 void escape(char *s, char *t) { int i, j; for(i = j = 0; t[i] != '\0'; i++) { switch(t[i]) { case '\n': s[j++] = '\\'; s[j++] = 'n'; break; case '\t': s[j++] = '\\'; s[j++] = ...
练习1-13  编写一个程序,打印输入中单词长度的水平直方图 #include<stdio.h> #define IN 1 /*在单词内*/ #define OUT 0 /*在单词外*/ #define MAXHIST 15 #define MAXWORD 11 int main() { int c, i, nc, state; int len; int maxvalue; int ovflow; int wl[MAXWORD]; state = OUT; nc = 0; ...

C语言qsort用法

一、对int类型数组排序 int num[100]; Sample: int cmp ( const void *a , const void *b ) { return *(int *)a - *(int *)b; } qsort(num,100,sizeof(num[0]),cmp); 二、对char类型数组排序(同int类型) char word[100]; Sample: int cmp( const void *a , const void *b ) { return *(char *)a - *(int *)b; } qsort(word,100,sizeo ...
Problem Description Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge). In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n. Input The input will consist of a series of integers n, one integer per line. Output For each case, output SUM(n) in one line, followed by a b ...
Problem Description Calculate A + B. Input Each line will contain two integers A and B. Process to end of file. Output For each case, output A + B in one line. Sample Input 1 1 Sample Output 2 import java.io.*; import java.util.*; public class Main { public static void main(String a ...
Global site tag (gtag.js) - Google Analytics