复试上机常用函数

版权声明:转载请注明出处 https://blog.csdn.net/nanhuaibeian/article/details/88903854
  1. 头文件
#include "stdio.h"
#include "string.h"
#include "malloc.h"
#include "math.h"
  1. 字符串常用函数
strlen()
strcmp()
if(strcmp(s1,s2)==0)//[如果s1大于s2则大于0]
strcpy(A,B)	//字符串B复制到A里
strlwr()
strupr()
s[20] = {"abc"}//给字符串赋初值
  1. 常用的数学函数
pow(10,2)//10的2次方
sqrt(10)//10的开方
a = fabs(-2);//取绝对值
  1. 文件的读写
FILE *fp;	//指向文件型数据的指针变量 
if((fp=fopen(filename,"w"))==NULL){
		printf("无法打开此文件\n");
		return; 
	}
//feof函数可以检查到文件读写位置标记是否移动到文件的末尾,即磁盘文件是否结束
while(!feof(in)) {
	ch = fgetc(in);	//从输入文件中读入一个字符,暂放在变量ch中
	fputc(ch,out);	//将ch写到输出文件中
	putchar(ch);
	}
	
if((fp=fopen("D:\\CC\\string.bat","w"))==NULL)指定其他磁盘文件注意路径格式

for(i=0; i<size; i++) {
		if((fwrite(&stu[i],sizeof(student),1,fp))!=1)
			printf("写入文件错误!!!");
	}

	for(i=0; i<size; i++) {
		fread(&stu[i],sizeof(student),1,fp);
		printf("%s %d %d\n",stu[i].name,stu[i].num,stu[i].age);	
	}
	fclose(fp);
  1. switch的使用
switch 使用
switch(f[i]){
			case 10: c = 'A';printf("%c ",c);break;
			default: printf("%d ",f[i]);break;
		} 
  1. memset函数初始化
//数组初始化
int b[20]={0};
char a[20];
memset(a,0,sizof(a));
//结构体初始化
hash h[10]
memset(h,-1,sizeof(hash)*10)
hash h;
memset(&h,-1,sizeof(hash))

猜你喜欢

转载自blog.csdn.net/nanhuaibeian/article/details/88903854
今日推荐