title: Read data from file and store values in C
body: <p>I have a file with a lot of lines like this:</p>
  
  <pre><code>1:458:187:131
  1:1124:384:63
  1:2300:514:31
  2:95:111:12
  ...
  </code></pre>
  
  <p>In each while of reading I use a function to use those values so that in next iteration it can be stored in the same variable.</p>
  
  <p>and then I have other with strings</p>
  
  <pre><code>6:City1:46:795:825:17134:8398:616:323:8791:5873
  7:City near London:507:1032
  8:NY:2595:64:193:684:1258:341:1125:1956:5079
  </code></pre>
  
  <p>It's the same process as before. Any help?</p>
  
  <pre><code>void readst()
   {
  
        int nn1, nn2,nn3,nn4;
          char str1[200], str2[200];
     char str[200];
     FILE *fp;
  
     fp = fopen("file.txt", "r");
      if(!fp) return 1; // bail out if file not found
     while(fgets(str,sizeof(str),fp) != NULL)
     {
        // strip trailing '\n' if it exists
        int len = strlen(str)-1;
        if(str[len] == '\n') 
           str[len] = 0;
           int n1, n2,n3,n4;
          char str1[200], str2[200];
  
          sscanf(str,"%d:%d:%d:%d",&amp;nn1,&amp;nn2,&amp;nn3,&amp;nn4);
          printf("%d\n%d\n%d\n%d\n",nn1,nn2,nn3,nn4);
  
       printf("\n%s", str);
     }
     fclose(fp);
   }
  </code></pre>