title: C Programming: Read file and search in a second file based on the data found
body: <p>I have two files, file1.txt and file2.txt:</p>
  
  <p>file1.txt:</p>
  
  <pre><code>1234:James Smith:100:110
  1111:Steve Jones:150:130
  4321:Bob Wilson:110:140
  </code></pre>
  
  <p>file2.txt</p>
  
  <pre><code>100;Area 1;0.00
  110;Area 2;3.00
  120;Area 3;4.75
  130;Area 4;5.95
  140;Area 5;10.00
  150;Area 6;12.00
  </code></pre>
  
  <p>What I would like to do is read file1.txt line by line and record some of the information to a file3.txt (output file) such as field 1 (number) and field 2 (name). To test that I could retrieve these, I used:</p>
  
  <pre><code>while (fscanf(file1, "%[^:]:%[^:]:%d:%d", number, name, &amp;on, &amp;off) == 4)
  {
    printf("Name contains: %s", name);
  }
  </code></pre>
  
  <p>As expected, this retrieved all of the "name" (field 2) values and displayed them on screen.
  I would now like to use the data stored in "on" and "off" to retrieve additional information from file2.txt. As you can see above, file1.txt fields 3 and 4 match up with field 1 in file2.txt. What I'm looking at getting in the final output file is:</p>
  
  <pre><code>1234 James Smith Area 1 to Area 2 3.00
  1111 Steve Jones Area 6 to Area 4 6.05
  4321 Bob Wilson Area 2 to Area 5 7.00
  </code></pre>
  
  <p>I'm not sure how to accomplish reading file1.txt line by line and performing the "check" with file2.txt at the same time and outputting. I also require a simple subtraction calculation in there as well.</p>
  
  <p>Any help would be greatly appreciated. I don't have much experience with fscanf, fgets, reading files, etc.</p>