zoukankan      html  css  js  c++  java
  • 数据文件——之读取文本文件中的整数

    代码:

     1 //This is c program code!
     2 /* *=+=+=+=+* *** *=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
     3   * 文档信息: *** :~/WORKM/stutyCode/cCode/recipesProblemSolution/chapter06/test6_9.c
     4   * 版权声明: *** :(魎魍魅魑)MIT
     5   * 联络信箱: *** :guochaoxxl@163.com
     6   * 创建时间: *** :2020年11月21日的上午10:28
     7   * 文档用途: *** :数据结构与算法分析-c语言描述
     8   * 作者信息: *** :guochaoxxl(http://cnblogs.com/guochaoxxl)
     9   * 修订时间: *** :2020年第46周 11月21日 星期六 上午10:28 (第326天)
    10   * 文件描述: *** :自行添加
    11  * *+=+=+=+=* *** *+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+*/
    12 #include <stdio.h>
    13 
    14 void closeState(int clo, FILE *fPtr){                                                   
    15     clo = fclose(fPtr);
    16     if(clo == -1){
    17     puts("File-closing failed.");
    18     }
    19     if(clo == 0){
    20     puts("File is closed successfully.");
    21     }
    22 
    23     return;
    24 }   
    25 int main(int argc, char **argv)
    26 {       
    27     FILE *fPtr = fopen("numbers.dat", "r");
    28     int col;
    29     if(fPtr != NULL){
    30         puts("File numbers.dat is opened successfully.");
    31         puts("Contents of file numbers.dat: ");
    32         int n;
    33         int num = fscanf(fPtr, "%d	", &n);
    34             
    35         while(num != EOF){
    36             printf("%d	",  n);
    37             num = fscanf(fPtr, "%d	", &n);
    38         }
    39         printf("
    ");
    40         closeState(col, fPtr);
    41     }else{
    42         puts("File-opening failed!");
    43     }   
    44     
    45     return 0;
    46 }
  • 相关阅读:
    PHP chgrp() 函数
    PHP basename() 函数
    PHP 5 Filesystem 函数
    PHP rewinddir() 函数
    PHP readdir() 函数
    PHP opendir() 函数
    PHP getcwd() 函数
    PHP dir() 函数
    PHP closedir() 函数
    PHP chroot() 函数
  • 原文地址:https://www.cnblogs.com/guochaoxxl/p/14054167.html
Copyright © 2011-2022 走看看