美文网首页
Day 3 1-3 Thursday 2019-01-17

Day 3 1-3 Thursday 2019-01-17

作者: 顾清_ | 来源:发表于2019-01-18 03:40 被阅读0次

    data.txt

    Pepsi: 80, okay
    Ginger Ale: 97, great
    Mt Due: 20, no
    Coke: 80, okay
    Moxie: 100, yes
    DrPep: 75, kinda
    

    parse.c

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    #define MAXLINESIZE 255
    #define MAXTOKENSIZE 100
    
    int main (int argc, char *argv[]) {
      char inString[MAXLINESIZE];
      char soda[MAXTOKENSIZE];
      char score[MAXTOKENSIZE];
      char comment[MAXTOKENSIZE];
    
      char *token;
    
      FILE *fp = fopen(argv[1], "r");
      if (fp == NULL) {
        printf("Bad filename\n");
        return 1;
      }
      while(fgets(inString, MAXLINESIZE, fp) != NULL) {
        token = strtok(inString, ":,\n");
        strcpy(soda, token);
        token = strtok(NULL, ":,\n");
        strcpy(score, token);
        token = strtok(NULL, ":,\n");
        strcpy(comment, token);
        printf("Soda: %s, Score: %s, Comment: %s\n", soda, score, comment);
      }
      return 0;
    }
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    #define MAXLINESIZE 255
    #define MAXTOKENSIZE 100
    
    int main (int argc, char *argv[]) {
      char inString[MAXLINESIZE];
      char soda[MAXTOKENSIZE];
      char score[MAXTOKENSIZE];
      char comment[MAXTOKENSIZE];
    
      FILE *fp = fopen(argv[1], "r");
      if (fp == NULL) {
        printf("Bad filename\n");
        return 1;
      }
      while(fgets(inString, MAXLINESIZE, fp) != NULL) {
        strcpy(soda, strtok(inString, ":,\n"));
        strcpy(score, strtok(NULL, ":,\n"));
        strcpy(comment, strtok(NULL, ":,\n"));
        printf("Soda: %s, Score: %s, Comment: %s\n", soda, score, comment);
      }
      return 0;
    }
    

    H e l l o
    H in String token -> l l o

    instring = Pepsi:85,okay/n
    strtok(inString, ":");
    inString token -> pepsi - 85, okay
    strtok(inString, ",");
    inString token -> Pepsi - 85, okay
    token - 85
    strtok(inString, "/n");
    pepsi -> 85 -> okay
    token - okay

    strcpy(current->data, strtok(inString, ":/n"));
    strcpy(current->value, atoi(strtok(NULL, ":/n")));
    

    相关文章

      网友评论

          本文标题:Day 3 1-3 Thursday 2019-01-17

          本文链接:https://www.haomeiwen.com/subject/zbhgdqtx.html