zoukankan      html  css  js  c++  java
  • 精通ObjectiveC系列 1) 文件读取

    #import <Foundation/Foundation.h>
    
    int main (int argc, const char * argv[])
    {
        FILE *wordFile = fopen ("/tmp/words.txt", "r");
        char word[100];
        
        while (fgets(word, 100, wordFile))
        {
            // strip off the trailing \n
            word[strlen(word) - 1] = '\0';
            NSLog (@"%s is %lu characters long", word, strlen(word));
        }
        
        fclose (wordFile);
        return (0);
    }

     文件内容:

    Joe-Bob "Handyman" Brown
    Jacksonville "Sly" Murphy
    Shinara Bain
    George "Guitar" Books

    运行结果:

    Joe-Bob "Handyman" Brown is 24 characters long
    Jacksonville "Sly" Murphy is 25 characters long
    Shinara Bain is 12 characters long
    George "Guitar" Books is 21 characters long

    技术改变世界
  • 相关阅读:
    第九周周记
    第七周周记
    第三次作业第一题
    第五周周记
    《世界是数字的》读后感想
    第十周周记
    迷茫
    测试作业
    价值观作业
    作业二 感想
  • 原文地址:https://www.cnblogs.com/davidgu/p/2918144.html
Copyright © 2011-2022 走看看