linux c 文件打包,文件打包与解压缩(实验报告-LinuxC编程)

1.

#include

#include

int cmp( const void *a , const void *b )

{

return *(char *)a - *(char *)b;

}

int main(){

char num[][11] = {"hello","world","we","dgut","university","abc","china","Shandon","Changqing","Jinan","computer"};

qsort(num,10,sizeof(num[0]),cmp);

for (int i = 0; i < 11; i++)

{

printf("%s、",num[i]);

}

}

2.

#include

#include

#include

#include

void root = NULL;

void *xmalloc(unsigned n)

{

void *p;

p = malloc(n);

if(p) return p;

fprintf(stderr,"insufficient memory\n");

exit(EXIT_FAILURE);

}

int compare(const void *pa,const void *pb)

{

if ((int *)pa < *(int *)pb)

return -1;

if (*(int *)pa > *(int *)pb)

return 1;

return 0;

}

void action(const void *nodep,const VISIT which,const int depth)

{

int *datap;

switch (which)

{

case preorder:

break;

case postorder:

datap = *(int **)nodep;

printf("%6d\n",*datap);

break;

case endorder:

break;

case leaf:

datap = *(int **)nodep;

printf("%6d\n",*datap);

break;

}

}

int main(void)

{

int i,*ptr;void val;

stand(time(NULL));

for ( i = 0; i < 12; i++)

{

ptr = xmalloc(sizeof(int));

*ptr = rand()&0xff;

val = tsearch((void *)ptr,&root,compare);

if (val == NULL)

{

exit(EXIT_FAILURE);

}else if (((int **)val) != ptr)

{

free(ptr);

}

}

twalk(root,action);

tdestory(root,free);

exit(EXIT_SUCCESS)

}

思考与练习题3.1:

685c50f17279ea361a958334997ec755.png

e9b28c31692f66978bd6fe018fd3c554.png

99679fc044eb44d6970a3fe2d1a747ce.png

bafeaaa144053030b11a6981e2511cd0.png

78dbc8faac5c525584e0a87514dbc6c0.png

思考与练习题3.6

SYNOPSIS

#include

int gettimeofday(struct timeval *tv, struct timezone *tz);

DESCRIPTION

The functions gettimeofday() and settimeofday() can get and set the

time as well as a timezone. The tv argument is a struct timeval (as

specified in ):

struct timeval {

time_t tv_sec; /* seconds */

suseconds_t tv_usec; /* microseconds */

};

and gives the number of seconds and microseconds since the Epoch (see

time(2)). The tz argument is a struct timezone:

struct timezone {

int tz_minuteswest; /* minutes west of Greenwich */

int tz_dsttime; /* type of DST correction */

};

include

include

include

int main()

{

struct timeval start,end;

gettimeofday(&start,NULL);

sleep(1);

gettimeofday(&end,NULL);

suseconds_t msec = end.tv_usec-start.tv_usec;

time_t sec = end.tv_sec-start.tv_sec;

printf("time used:%u.%us\n",sec,msec);

return 0;

}

3.7:

#include

#include

int cmp ( const void *a , const void *b )

{

return *(float *)a > *(float *)b ? 1 : -1;;

}

int main(){

float num[10] = {90.9,51.8,32.7,83.6,94.5,45.4,36.3,47.2,28.1,19.0};

qsort(num,10,sizeof(num[0]),cmp);

for (int i = 0; i < 10; i++)

{

printf("%0.1f、",num[i]);

}

3.17

argc=4

argv[3]=complex param

argv[2]=praram2

argv[1]=param1

PHONE =10086

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值