Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2873fbb

Browse files
Update Solution.md
1 parent 9847e78 commit 2873fbb

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

β€ŽPROGRAMS/10. Files/Solution.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,20 +235,17 @@ void check(char filename1[], char filename2[])
235235
// Read dates from the second file and count the number of events on each date
236236
while (fscanf(fp2, "%d\n", &day1) != EOF)
237237
{
238+
rewind(fp1); // Rewind the first input file to start reading from the beginning
239+
count = 0; // Reset the event count for the current date
240+
238241
// Read events from the first file and check if they match the current date
239242
while (fscanf(fp1, "%d, %[^\n]\n", &day2, events) != EOF)
240243
{
241244
if (day2 == day1) // If the event date matches the current date, increment the count
242245
count++;
243-
else // If the event date does not match the current date, print the count and reset it
244-
{
245-
printf("%d %d\n", day1, count);
246-
count = 1;
247-
break;
248-
}
249246
}
247+
printf("%d %d\n", day1, count); // Print the current date and event count
250248
}
251-
printf("%d %d\n", day1, count); // Print the final count
252249
}
253250

254251
int main()

0 commit comments

Comments
(0)

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /