Skip to content

Commit c42da6f

Browse files
Update weeklycontent.html
1 parent 41a55b2 commit c42da6f

File tree

1 file changed

+164
-9
lines changed

1 file changed

+164
-9
lines changed

weeklycontent.html

Lines changed: 164 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,10 +2232,165 @@ <h3>Output:</h3>
22322232
</div>
22332233
<div id="saturday-content-week5" class="day-content day-section">
22342234
<h2>Brain Cache</h2>
2235-
<div class="button-container" style="text-align: center; padding: 15px;">
2236-
<p style="text-align: center; font-style: italic; color: #555;">Quiz goes live <strong>today</strong> at <strong>6.00 PM IST</strong>!</p>
2237-
<button class="nav-button" onclick="window.location.href='quiz.html';">Quiz</button> </div>
2238-
</div>
2235+
<div class="content-block">
2236+
<h3>1. Which of the following statements about C structures is true?</h3>
2237+
<ol>
2238+
<li>A structure can only contain variables of the same data type.</li>
2239+
<li><strong>The `struct` keyword is used to define a new data type.</strong></li>
2240+
<li>Members of a structure are accessed using the `->` operator for all cases.</li>
2241+
<li>Structures cannot be passed as arguments to functions.</li>
2242+
</ol>
2243+
</div>
2244+
2245+
<div class="content-block">
2246+
<h3>2. What will be the output of the following code snippet?</h3>
2247+
<pre class="code-block"><code>#include &lt;stdio.h&gt;
2248+
2249+
int main() {
2250+
FILE *fp;
2251+
fp = fopen("data.txt", "r");
2252+
if (fp == NULL) {
2253+
printf("Can't open file \n");
2254+
} else {
2255+
fprintf(fp, "Hello, world! ");
2256+
printf("Written to file \n");
2257+
fclose(fp);
2258+
}
2259+
return 0;
2260+
}</code></pre>
2261+
<ol>
2262+
<li>Written to file</li>
2263+
<li><strong>Can't open file</strong></li>
2264+
<li>File gets created and "Hello, world! " is written into it</li>
2265+
<li>Compile-time error</li>
2266+
</ol>
2267+
</div>
2268+
2269+
<div class="content-block">
2270+
<h3>3. What might happen when the following C program is executed?</h3>
2271+
<pre class="code-block"><code>#include &lt;stdio.h&gt;
2272+
2273+
int main() {
2274+
FILE *fptr;
2275+
char data[100];
2276+
2277+
fptr = fopen("myfile.txt", "w"); // open in write mode
2278+
if (fptr == NULL) {
2279+
printf("Error opening file!\n");
2280+
return 1;
2281+
}
2282+
2283+
printf("Enter some text to write into the file: ");
2284+
fgets(data, sizeof(data), stdin);
2285+
fprintf(fptr, "%s", data);
2286+
fclose(fptr);
2287+
printf("Data written to file successfully.\n");
2288+
2289+
fptr = fopen("myfile.txt", "r"); // open in read mode
2290+
if (fptr == NULL) {
2291+
printf("Error opening file!\n");
2292+
return 1;
2293+
}
2294+
2295+
printf("Reading from the file:\n");
2296+
while (fgets(data, sizeof(data), fptr) != NULL) {
2297+
printf("%s", data);
2298+
}
2299+
fclose(fptr);
2300+
2301+
return 0;
2302+
}</code></pre>
2303+
<ol>
2304+
<li><strong>The program writes user input to a file and reads it back successfully.</strong></li>
2305+
<li>The program writes data to the file but fails to read it.</li>
2306+
<li>The program crashes immediately due to a syntax error.</li>
2307+
<li>The file is opened in append mode, so it keeps adding new data every time.</li>
2308+
</ol>
2309+
</div>
2310+
2311+
<div class="content-block">
2312+
<h3>4. What is the primary reason for structure padding in C?</h3>
2313+
<ol>
2314+
<li>To improve code readability</li>
2315+
<li>To reduce memory usage</li>
2316+
<li><strong>To ensure proper alignment of structure members in memory</strong></li>
2317+
<li>To increase execution speed</li>
2318+
</ol>
2319+
</div>
2320+
2321+
<div class="content-block">
2322+
<h3>5. What is the purpose of the `fprintf` function in `writeStudentToFile()`?</h3>
2323+
<pre class="code-block"><code>#include &lt;stdio.h&gt;
2324+
#include &lt;string.h&gt;
2325+
2326+
struct Student {
2327+
int id;
2328+
char name[50];
2329+
float marks;
2330+
};
2331+
2332+
void writeStudentToFile() {
2333+
struct Student s;
2334+
2335+
printf("Enter Student ID: ");
2336+
scanf("%d", &s.id);
2337+
2338+
printf("Enter Student Name: ");
2339+
scanf(" %[^\n]", s.name);
2340+
2341+
printf("Enter Marks: ");
2342+
scanf("%f", &s.marks);
2343+
2344+
FILE *fp = fopen("student.txt", "w");
2345+
if (fp == NULL) {
2346+
printf("Error opening file!\n");
2347+
return;
2348+
}
2349+
2350+
fprintf(fp, "%d\n%s\n%.2f\n", s.id, s.name, s.marks);
2351+
fclose(fp);
2352+
printf("Student data saved successfully.\n\n");
2353+
}
2354+
2355+
void readStudentFromFile() {
2356+
struct Student s;
2357+
FILE *fp = fopen("student.txt", "r");
2358+
2359+
if (fp == NULL) {
2360+
printf("Error opening file!\n");
2361+
return;
2362+
}
2363+
2364+
fscanf(fp, "%d\n", &s.id);
2365+
fgets(s.name, sizeof(s.name), fp);
2366+
fscanf(fp, "%f", &s.marks);
2367+
2368+
if (s.name[strlen(s.name) - 1] == '\n') {
2369+
s.name[strlen(s.name) - 1] = '\0';
2370+
}
2371+
2372+
fclose(fp);
2373+
2374+
printf("Student Data from File:\n");
2375+
printf("ID: %d\n", s.id);
2376+
printf("Name: %s\n", s.name);
2377+
printf("Marks: %.2f\n", s.marks);
2378+
}
2379+
2380+
int main() {
2381+
writeStudentToFile();
2382+
readStudentFromFile();
2383+
return 0;
2384+
}</code></pre>
2385+
<ol>
2386+
<li>To read data from a file</li>
2387+
<li>To print data to the console</li>
2388+
<li><strong>To write formatted data to a file</strong></li>
2389+
<li>To close the file after writing</li>
2390+
</ol>
2391+
</div>
2392+
2393+
</div>
22392394

22402395
</div>
22412396
</div>
@@ -2263,11 +2418,11 @@ <h2>Brain Cache</h2>
22632418
let disabledWeekId = 'null'; // Example: Week 4 is disabled
22642419
// Define an array of disabled days for a given week (e.g., ['tuesday', 'thursday'] for week1)
22652420
const disabledDays = {
2266-
'week1': ['monday','tuesday','wednesday','thursday','friday','saturday'], // Example: Tuesday and Thursday are disabled for Week 1
2267-
'week2': ['monday','tuesday','wednesday','thursday','friday','saturday'],
2268-
'week3': ['monday','tuesday','wednesday','thursday','friday','saturday'],
2269-
'week4': ['monday','tuesday','wednesday','thursday','friday','saturday'],
2270-
'week5': ['monday','tuesday','wednesday','thursday','friday'],
2421+
'week1': ['monday','tuesday','wednesday','thursday','friday','saturday'], // Example: Tuesday and Thursday are disabled for Week 1
2422+
'week2': ['monday','tuesday','wednesday','thursday','friday','saturday'],
2423+
'week3': ['monday','tuesday','wednesday','thursday','friday','saturday'],
2424+
'week4': ['monday','tuesday','wednesday','thursday','friday','saturday'],
2425+
'week5': ['monday','tuesday','wednesday','thursday','friday','saturday'],
22712426
};
22722427
// --- END CONTROL KEYWORD ---
22732428

0 commit comments

Comments
 (0)