编程笔记
-
将动态内存分配给malloc()函数的变量时执行类型转换
#include <stdio.h> #include <stdlib.h> int main()// { char *name; name = (char *) malloc(80); }
-
类型转换:数字转为字符,字符转为数字
#include <stdio.h> int main() { int number = 86; char letter = 'M'; printf("/n86 type-casted to char is: %c/n", (char) number); printf("/n'M' type-casted to int i…
-
在整数除法期间未使用类型转换时会怎么样?
#include <stdio.h> int main() // { int x = 12; int y = 5; printf("/nWithout Type-Casting/n"); printf("12 // 5 = %.2f/n", x/y); printf("/nWith Type-Casting/n"); pri…
-
从int到float的类型转换
#include <stdio.h> int main() { int x = 12; int y = 5; float result = 0; result = (float) x / (float) y; printf("%f", result); }
-
将一种数据类型转换为另一种类型
#include <stdio.h> int main(void) /* print i and i/2 with fractions */ { int i; for (i = 1; i <= 50; ++i) printf("%d / 2 is: %f/n", i, (float)i / 2); return 0; }
-
使用宽字符
#include <stdio.h> #include <wchar.h> int main(void){ wchar_t value = L'/u00f6'; wchar_t wch = L'I'; wchar_t w_arr[20] = L"am wide!"; printf("%lc %ls %lc/n&…
-
在一个字符串中查找一个宽字符串的出现次数
#include <stdio.h> #include <wchar.h> #include <wctype.h> #define TEXT_SIZE 100 #define SUBSTR_SIZE 40 wchar_t *wstr_towupper(wchar_t *wstr, size_t size); // Wide string to uppercas…
-
宽字符的操作
#include <stdio.h> #include <wchar.h> #include <wctype.h> int main(void){ wchar_t ch = 0; // Stores a character fwprintf(stdout, L"Enter a character:/n "); fwscanf(stdin, …
-
测试日期和时间函数
#include <stdio.h> #include <time.h> #include <math.h> #include <ctype.h> int main(void){ time_t calendar_start = time(NULL); // Initial calendar time clock_t cpu_start = cloc…
-
tm结构的成员
成员 描述 tm_sec 24小时制分钟后的秒数(0到60)。对于正闰秒支持,该值最高为60。 tm_min 每小时24小时制(0至59分钟) tm_hour 24小时制的小时(0到23) tm_mday 每月的某一天(1到31) tm_mon 月份(0到11) tm_year 年份…