C语言笔记

 

函数说明
gcvt()将浮点型数转换为字符串(四舍五入)
index()查找字符串并返回首次出现的位置
rindex()查找字符串并返回最后一次出现的位置
strcasecmp()判断字符串是否相等(忽略大小写)
strcpy()复制字符串
strdup()复制字符串
strncasecmp()比较字符串的前n个字符

 

http://www.cnblogs.com/Shirlies/p/4282182.html

 

1. 打开文件

int openFile1(void)
{
    FILE *file;
    int ch;
    if((file=fopen("test.txt", "r")) == NULL)
    {
        printf("the file can't be opened!\n");
        exit(1);
    }

     //int fgetc(FILE *stream); 将把由流指针指向的文件中的一个字符读出    
    while((ch=fgetc(file)) != EOF)
    {
        putchar(ch);
        //fputc(ch,stdout);
    }
    
    if(fclose(file) == 0)
    {
        printf("Succeed closed!\n");
    }
    
    //关闭多个文件,fcloseall()
    //fcloseall();
    
    return 0;
}

int openFile2(void)
{
    FILE *file;
    char str[128];
    
    if((file=fopen("test.txt", "r")) == NULL)
    {
        printf("the file can't be opened!\n");
        exit(1);
    }
    
    while(!feof(file))
    {
        if(fgets(str,2,file)!=NULL)
        printf("%s\n", str);
    }
        
    if(fclose(file)!=0) {  
        printf("File cannot be closed\n");   
        exit(1);   
    }   
    else  
        printf("File is now closed\n"); 
}

 

转载于:https://www.cnblogs.com/xinzi7/p/6662963.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值