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 544dd48

Browse files
Update Solution.md
1 parent 2873fbb commit 544dd48

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,27 @@ int main()
212212

213213

214214
## Explanation:
215+
This C program reads events from one input file and dates from another input file, and counts the number of events that occur on each date. Here is the main logic of the code in detail:
216+
217+
1. The `check` function takes the names of the two input files as arguments.
218+
2. The `check` function opens both input files for reading.
219+
3. The `check` function initializes variables to store the current date, event count, and event name.
220+
4. The `check` function enters a loop to read dates from the second input file using `fscanf`.
221+
5. For each date read from the second input file, the `check` function rewinds the first input file to start reading from its beginning and resets the event count for the current date.
222+
6. The `check` function enters a nested loop to read events from the first input file using `fscanf`.
223+
7. For each event read from the first input file, the `check` function checks if its date matches the current date.
224+
8. If the event date matches the current date, the `check` function increments the event count.
225+
9. After all events have been read from the first input file for one date, the `check` function prints the current date and event count using `printf`.
226+
10. The `main` function prompts the user to enter the names of the two input files using `printf` and `scanf`.
227+
11. The `main` function appends ".txt" to both filenames using `strcat`.
228+
12. The `main` function calls the `check` function with both filenames as arguments.
215229

216230
## Time and Space Complexity:
217231
### `Time Complexity`:
232+
The time complexity of this code is O(nm), where n is the number of dates in the second input file and m is the number of events in the first input file, because each date requires reading all events from the first input file once.
218233

219234
### `Space Complexity`:
235+
The space complexity of this code is O(1), because it uses a constant amount of memory (i.e., memory usage does not depend on the size of either input). However, this analysis assumes that all strings (i.e., event names) have a fixed maximum length, as specified by their respective character arrays.
220236

221237
## Code:
222238
```c

0 commit comments

Comments
(0)

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