C语言学习-day18-函数1

今天开始学习函数。

函数是一个大型程序中某部分代码,由一个或者多个语句快组成,负责完成某项特定恩物,相较于其他代码具备独立性。

一般有输入参数并有返回值。

库函数:对于大量频繁使用的函数比如printf,直接调用一个库,然后可以不用编译函数直接使用库中函数。

库函数分类:

IO函数输入输出函数:printf、scanf、getchar、putchar

字符串操作函数:strcmp、strlen

字符操作函数:toupper

内存操作函数:memcpy、memcmp、memset

时间操作函数:time

数学函数:sqrt、pow

其他库函数

接下来学习下如何使用www.cplusplus.com学习函数

首先打开网页

发现跟比特课件上的完全不同也没有search。不要慌,点一下右上角的legacy version切换成老的就可以搜索啦。然后做两个举例下。

Strcpy:

可以通过阅读解释知道这个函数是干什么的。本人留学生这点初中英语还是手拿把掐的。

char * strcpy ( char * destination, const char * source );

Copy string

Copies the C string pointed by source into the array pointed by destination, including the terminating null character (and stopping at that point).

To avoid overflows, the size of the array pointed by destination shall be long enough to contain the same C string as source (including the terminating null character), and should not overlap in memory with source.

简单的说就是:把source的字符复制然后放到destination里去。我们来试一下:

int main()

{

    char arr1[20] = { 0 };

    char arr2[] = "hello bit";

    strcpy(arr1, arr2);

    printf("%s", arr1);

    return 0;

}

运行结果:

Ok。

注意:一定要先引用头文件,这个函数不是自带的,使用的话必须引用一下。如图我在开始就引用了includea<string.h>所以我才可以用,没有引用会报错。

Memset:

我们试一下:

int main()

{

    char arr[] = "hello bit";

    memset(arr, 'x', 5);

    printf("%s", arr);

    return 0;

}

把前五个字都换成了x

  • 15
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值