tarinaretake

git clone https://git.tarina.org/tarinaretake
Log | Files | Refs | README | LICENSE

main_new.c (1006B)


      1 #define _GNU_SOURCE
      2 #include <stdio.h>
      3 #include <stdlib.h>
      4 #include <string.h>
      5 #include <unistd.h>
      6 
      7 int main(void)
      8 {
      9     FILE * fp;
     10     FILE * fp2;
     11     char * line = NULL;
     12     size_t len = 0;
     13     ssize_t read;
     14     int linenr = 0;
     15     int selected;
     16     char newread[500];
     17     char oldread[500];
     18 
     19     while (1) {
     20         linenr = 0;
     21         fp = fopen("interface", "r");
     22         fread(newread, sizeof(char), 500, fp);
     23         fclose(fp);
     24         if (strcmp(newread, oldread) != 0) {
     25             strcpy(oldread, newread);
     26             fp2 = fopen("interface", "r");
     27             while ((read = getline(&line, &len, fp2)) != -1) {
     28                 if (linenr == 0)
     29                     selected = atoi(line);
     30                 if (linenr == selected)
     31                     printf("selected");
     32                 printf("%zu",read);
     33                 printf(line);
     34                 linenr += 1;
     35             }
     36             fclose(fp2);
     37             //if (line)
     38             //    free(line);
     39         }
     40     usleep(20000);
     41     }
     42 }