File Input/Output Functions: fgetc, fputc, fgets, fputs, fprintf Notes in Hindi & English : फाइल I/O फंक्शन्स: fgetc, fputc, fgets, fputs, fprintf, fscanf और 20 महत्वपूर्ण MCQ प्रश्न (Rajasthan IT Exam)

Post a Comment

PGDCA, BCA, B-Tech, MCA, M-Tech, B.Sc computer science राजस्थान सूचना सहायक व कंप्यूटर शिक्षक विशेष नोट्स: इस अध्याय में हम File Input/Output Functions: fgetc, fputc, fgets, fputs, fprintf (फाइल I/O फंक्शन्स: fgetc, fputc, fgets, fputs, fprintf, fscanf) की संपूर्ण थ्योरी, मुख्य तकनीकी बिंदु, तुलनात्मक तालिका और विगत परीक्षाओं के पैटर्न पर आधारित 20 अति-महत्वपूर्ण बहुविकल्पीय प्रश्न (MCQs) विस्तृत हिंदी व अंग्रेजी व्याख्या सहित पढ़ेंगे।

Overview: Standard C text file I/O relies on buffered stream functions declared in <stdio.h> using a FILE pointer obtained from fopen() and released with fclose(). Functions such as fgetc, fputc, fgets, fputs, fprintf, and fscanf provide character-level, line-level, and formatted reading or writing across text streams.

अध्याय सार: मानक C में टेक्स्ट फाइल I/O <stdio.h> हेडर के बफर्ड स्ट्रीम फंक्शन्स पर आधारित होता है, जो fopen() से प्राप्त FILE पॉइंटर का उपयोग करके fclose() से बंद किया जाता है। fgetc, fputc, fgets, fputs, fprintf और fscanf जैसे फंक्शन्स कैरेक्टर, लाइन और फॉर्मेटेड डेटा को टेक्स्ट स्ट्रीम से पढ़ने व लिखने की सुविधा देते हैं।

File Input/Output Functions: fgetc, fputc, fgets, fputs, fprintf: Detailed Notes & Architecture (फाइल I/O फंक्शन्स: fgetc, fputc, fgets, fputs, fprintf, fscanf)

1. Stream Opening Modes and Character I/O (fgetc, fputc) (स्ट्रीम ओपनिंग मोड्स और कैरेक्टर I/O (fgetc, fputc))

[EN] Every file operation begins by opening a stream with fopen(filename, mode), where "r" reads an existing file, "w" creates or truncates a file, and "a" appends to the end, returning NULL on failure. The fgetc(FILE *fp) function reads the next character as an unsigned char cast to int, returning EOF (commonly -1) on end-of-file or read error. Storing fgetc() return values in an int rather than a char is mandatory so EOF cannot collide with the valid byte value 255 (0xFF). Conversely, fputc(int ch, FILE *fp) writes a single byte converted to unsigned char and returns the written character or EOF if writing fails.

[HI] प्रत्येक फाइल ऑपरेशन fopen(filename, mode) से शुरू होता है, जहाँ "r" पढ़ने के लिए, "w" नई फाइल बनाने या पुरानी खाली करने के लिए, और "a" अंत में जोड़ने के लिए उपयोग होता है तथा विफलता पर NULL लौटाता है। fgetc(FILE *fp) अगला कैरेक्टर unsigned char के रूप में पढ़कर int में कास्ट करके लौटाता है और फाइल अंत या त्रुटि पर EOF (सामान्यतः -1) देता है। fgetc() का रिटर्न मान char के बजाय int में स्टोर करना आवश्यक है ताकि EOF की पहचान वैध बाइट 255 (0xFF) से टकराए नहीं। इसके विपरीत, fputc(int ch, FILE *fp) एक कैरेक्टर फाइल में लिखता है और सफलता पर वही कैरेक्टर या विफलता पर EOF लौटाता है।

2. Line-Oriented String I/O (fgets and fputs) (लाइन-आधारित स्ट्रिंग I/O (fgets और fputs))

[EN] The fgets(char *buf, int n, FILE *fp) function safely reads at most n - 1 characters into buf until a newline ('\n') or EOF is encountered, then appends a null terminator ('\0'). Unlike the deprecated gets() function, fgets() enforces buffer bounds to prevent stack buffer overflows and retains the newline character inside buf if space permits. It returns buf on success and NULL when EOF is reached before any character is read or when an error occurs. On the output side, fputs(const char *str, FILE *fp) writes the null-terminated string without the '\0' byte and, unlike puts(), does not automatically append a newline.

[HI] fgets(char *buf, int n, FILE *fp) सुरक्षित रूप से अधिकतम n - 1 कैरेक्टर तब तक पढ़ता है जब तक न्यूलाइन ('\n') या EOF न आ जाए, और अंत में नल टर्मिनेटर ('\0') जोड़ देता है। असुरक्षित और हटाए जा चुके gets() फंक्शन के विपरीत, fgets() बफर सीमा की जांच करके स्टैक बफर ओवरफ्लो को रोकता है तथा जगह होने पर '\n' को बफर में सुरक्षित रखता है। सफलता पर यह buf का पता और बिना पढ़े EOF या त्रुटि आने पर NULL लौटाता है। आउटपुट के लिए fputs(const char *str, FILE *fp) बिना '\0' के स्ट्रिंग लिखता है और puts() के विपरीत अपने आप न्यूलाइन नहीं जोड़ता।

3. Formatted File I/O (fprintf and fscanf) (फॉर्मेटेड फाइल I/O (fprintf और fscanf))

[EN] The fprintf(FILE *fp, const char *fmt, ...) function mirrors printf() by converting integers, floats, and strings into human-readable text according to format specifiers such as %d, %f, and %s before writing to fp. It returns the total number of characters written on success or a negative integer if an output error occurs. Similarly, fscanf(FILE *fp, const char *fmt, ...) parses formatted tokens from the stream into variable addresses and returns the count of successfully matched and assigned input items, or EOF if failure precedes the first conversion. Because %s in fscanf stops at whitespace, developers combine width limits like %31s or switch to fgets() + sscanf() for safer line parsing.

[HI] fprintf(FILE *fp, const char *fmt, ...) बिल्कुल printf() की तरह %d, %f और %s जैसे फॉर्मेट स्पेसिफायर्स का उपयोग करके डेटा को टेक्स्ट में बदलकर स्ट्रीम में लिखता है। सफलता पर यह लिखे गए कुल कैरेक्टर्स की संख्या और त्रुटि होने पर ऋणात्मक पूर्णांक लौटाता है। इसी प्रकार fscanf(FILE *fp, const char *fmt, ...) स्ट्रीम से फॉर्मेटेड डेटा पढ़कर वेरिएबल एड्रेस में भरता है तथा सफलतापूर्वक असाइन किए गए आइटम्स की संख्या या पहले कन्वर्जन से पहले विफलता पर EOF लौटाता है। चूंकि fscanf में %s व्हाइटस्पेस पर रुक जाता है, सुरक्षित पार्सिंग के लिए %31s जैसी चौड़ाई सीमा या fgets() + sscanf() का प्रयोग किया जाता है।

4. Error Checking, EOF Semantics, and Resource Closing (त्रुटि जांच, EOF नियम और रिसोर्स क्लोजिंग)

[EN] A common C programming pitfall is writing while (!feof(fp)) before reading, which causes the loop body to execute one extra time after the last valid read because feof(fp) becomes non-zero only after a read attempt hits EOF. The idiomatic pattern checks the return value of the input function directly, such as while ((ch = fgetc(fp)) != EOF) or while (fgets(line, sizeof(line), fp) != NULL). After a read returns EOF or NULL, callers can distinguish genuine end-of-file from hardware/stream I/O failures using feof(fp) versus ferror(fp). Finally, calling fclose(fp) flushes user-space stdio buffers to the OS kernel and releases the underlying file descriptor to prevent descriptor leaks.

[HI] C प्रोग्रामिंग में एक आम गलती पढ़ने से पहले while (!feof(fp)) लिखना है, जिससे अंतिम वैध डेटा के बाद लूप एक अतिरिक्त बार चलता है क्योंकि feof(fp) तभी सेट होता है जब रीड ऑपरेशन EOF से टकराता है। सही तरीका इनपुट फंक्शन का रिटर्न मान सीधे जांचना है, जैसे while ((ch = fgetc(fp)) != EOF) या while (fgets(line, sizeof(line), fp) != NULL)। EOF या NULL मिलने के बाद feof(fp) और ferror(fp) के माध्यम से वास्तविक फाइल समाप्ति और हार्डवेयर/I/O त्रुटि में अंतर किया जा सकता है। अंत में fclose(fp) कॉल करने से बफर्ड डेटा डिस्क पर फ्लश होता है और ऑपरेटिंग सिस्टम का फाइल डिस्क्रिप्टर मुक्त हो जाता है।

Syntax, Formula & Technical Example (File Input/Output Functions: fgetc, fputc, fgets, fputs, fprintf)

#include <stdio.h>
int main(void) {
    FILE *fp = fopen("notes.txt", "w");
    if (!fp) return 1;
    fprintf(fp, "Marks: %d\n", 95);
    fputs("Result: Pass\n", fp);
    fclose(fp);
    char buf[64];
    fp = fopen("notes.txt", "r");
    while (fp && fgets(buf, sizeof(buf), fp) != NULL) fputs(buf, stdout);
    if (fp) fclose(fp);
    return 0;
}

File Input/Output Functions: fgetc, fputc, fgets, fputs, fprintf Quick Reference & Comparison Table

FunctionPrimary Role & Return ValueCritical Exam Detail
fgetc(fp)Reads 1 byte as int; returns char or EOFMust store in int, not char, to catch EOF (-1)
fgets(s, n, fp)Reads up to n-1 chars; returns s or NULLRetains '\n' if read and appends '\0'
fputs(s, fp)Writes string; returns non-negative or EOFDoes NOT append automatic newline like puts()
fprintf(fp, fmt, ...)Writes formatted text; returns char countReturns negative value if stream write fails

File Input/Output Functions: fgetc, fputc, fgets, fputs, fprintf Top 20 Bilingual MCQs with Answers

Q1. What should be the data type of the variable storing the return value of fgetc(fp)?

(fgetc(fp) के रिटर्न मान को स्टोर करने वाले वेरिएबल का डेटा टाइप क्या होना चाहिए?)

(A) void*

(B) char

(C) int

(D) unsigned char

Correct Answer: (C)

[EN] fgetc() returns an unsigned char cast to int, or EOF (-1), so an int variable is needed to distinguish EOF from byte 0xFF.

[HI] fgetc() unsigned char को int में बदलकर या EOF (-1) लौटाता है, इसलिए 0xFF बाइट और EOF में अंतर करने के लिए int आवश्यक है।

Q2. If char buf[20]; is passed to fgets(buf, 20, fp), what is the maximum number of characters read from the file before the null terminator?

(यदि fgets(buf, 20, fp) में char buf[20]; पास किया जाए, तो नल टर्मिनेटर से पहले फाइल से अधिकतम कितने कैरेक्टर पढ़े जाएंगे?)

(A) 20

(B) 21

(C) 19

(D) 18

Correct Answer: (C)

[EN] fgets(buf, n, fp) reads at most n - 1 characters (19 here) so the 20th byte is reserved for the trailing '\0'.

[HI] fgets(buf, n, fp) अधिकतम n - 1 (यहाँ 19) कैरेक्टर पढ़ता है ताकि अंतिम 20वां बाइट '\0' के लिए सुरक्षित रहे।

Q3. Which standard I/O function writes a string to a file WITHOUT automatically appending a newline character?

(निम्न में से कौन-सा मानक I/O फंक्शन बिना स्वचालित न्यूलाइन जोड़े फाइल में स्ट्रिंग लिखता है?)

(A) printf()

(B) puts()

(C) fprintf() with \n

(D) fputs()

Correct Answer: (D)

[EN] Unlike puts(), which always appends a newline to stdout, fputs(str, fp) writes only the characters of str up to '\0'.

[HI] puts() के विपरीत (जो हमेशा stdout पर न्यूलाइन जोड़ता है), fputs(str, fp) केवल '\0' से पहले के कैरेक्टर लिखता है।

Q4. What does fopen("log.txt", "w") do if "log.txt" already exists with prior content?

(यदि "log.txt" पहले से डेटा के साथ मौजूद है, तो fopen("log.txt", "w") क्या करता है?)

(A) Opens the file in read-only mode

(B) Fails and returns NULL

(C) Truncates the existing file to zero length and opens it for writing

(D) Appends new data at the end of the file

Correct Answer: (C)

[EN] Opening an existing file in "w" mode discards all previous content by truncating its length to zero.

[HI] "w" मोड में पहले से मौजूद फाइल खोलने पर उसका पुराना सारा डेटा मिटाकर लंबाई शून्य कर दी जाती है।

Q5. What does fscanf(fp, "%d %s", &id, name) return upon successfully reading both values?

(दोनों मान सफलतापूर्वक पढ़ने पर fscanf(fp, "%d %s", &id, name) क्या लौटाता है?)

(A) 0

(B) 2

(C) 1

(D) Total bytes read

Correct Answer: (B)

[EN] fscanf() returns the number of input fields successfully converted and assigned (2 in this case).

[HI] fscanf() सफलतापूर्वक कन्वर्ट और असाइन किए गए इनपुट आइटम्स की संख्या (यहाँ 2) लौटाता है।

Q6. Which function distinguishes whether an EOF return from fgetc() was caused by reaching end-of-file or by an I/O read failure?

(fgetc() से EOF मिलने पर यह पहचानने के लिए किस फंक्शन का उपयोग होता है कि कारण फाइल का अंत है या I/O त्रुटि?)

(A) ftell(fp)

(B) fflush(fp)

(C) fclose(fp)

(D) ferror(fp)

Correct Answer: (D)

[EN] ferror(fp) returns non-zero when a read/write error indicator is set on the stream, whereas feof(fp) checks only the EOF indicator.

[HI] ferror(fp) स्ट्रीम पर I/O त्रुटि होने पर नॉन-जीरो मान लौटाता है, जबकि feof(fp) केवल EOF फ्लैग की जांच करता है।

Q7. Why is using while (!feof(fp)) as the loop condition before calling fgets() considered a logic bug?

(fgets() कॉल करने से पहले लूप कंडीशन में while (!feof(fp)) का उपयोग करना लॉजिक बग क्यों माना जाता है?)

(A) feof(fp) becomes true only after a read attempt passes EOF, causing one extra iteration

(B) feof(fp) closes the stream automatically

(C) feof(fp) always returns 1 on text files

(D) fgets() ignores the EOF flag completely

Correct Answer: (A)

[EN] The EOF indicator is set only when a read operation tries to read past the end of the file, so checking !feof(fp) upfront repeats the last buffer or processes garbage.

[HI] EOF इंडिकेटर तभी सेट होता है जब रीड फंक्शन फाइल अंत से आगे पढ़ने का प्रयास करता है, जिससे लूप एक अतिरिक्त बार चल जाता है।

Q8. Which header file defines the FILE structure, EOF macro, and functions like fopen(), fgetc(), and fprintf()?

(FILE स्ट्रक्चर, EOF मैक्रो और fopen(), fgetc(), fprintf() जैसे फंक्शन्स किस हेडर फाइल में परिभाषित होते हैं?)

(A) <stdio.h>

(B) <fcntl.h>

(C) <string.h>

(D) <stdlib.h>

Correct Answer: (A)

[EN] Standard buffered C stream I/O types, macros, and functions reside in <stdio.h>.

[HI] मानक C बफर्ड स्ट्रीम I/O के टाइप्स, मैक्रोज़ और फंक्शन्स <stdio.h> में परिभाषित होते हैं।

Q9. What is the return value of fputc('A', fp) if the write succeeds?

(यदि लिखना सफल हो जाए तो fputc('A', fp) क्या लौटाता है?)

(A) A pointer to fp

(B) 0

(C) The ASCII integer value of 'A' (65)

(D) 1

Correct Answer: (C)

[EN] On success, fputc(ch, fp) returns the character written converted to unsigned char and cast to int.

[HI] सफलता पर fputc(ch, fp) लिखा गया कैरेक्टर unsigned char से int में बदलकर (यहाँ 'A' का मान 65) लौटाता है।

Q10. What happens when fopen("missing.txt", "r") is called on a file that does not exist?

(जब किसी ऐसी फाइल पर fopen("missing.txt", "r") कॉल किया जाता है जो मौजूद नहीं है, तो क्या होता है?)

(A) It returns NULL without creating the file

(B) It returns EOF

(C) It creates an empty missing.txt file

(D) It terminates the program immediately

Correct Answer: (A)

[EN] Read mode "r" requires the file to exist; otherwise fopen() fails and returns a NULL pointer.

[HI] रीड मोड "r" के लिए फाइल का पहले से मौजूद होना जरूरी है; अन्यथा fopen() विफल होकर NULL पॉइंटर लौटाता है।

Q11. Which value does fgets() return when it reaches end-of-file before reading any characters?

(बिना कोई कैरेक्टर पढ़े फाइल के अंत (EOF) पर पहुंचने पर fgets() क्या लौटाता है?)

(A) NULL

(B) An empty string ""

(C) EOF (-1)

(D) 0

Correct Answer: (A)

[EN] Unlike fgetc() and fputc() which return integer EOF, fgets() returns a char* pointer and indicates EOF/error by returning NULL.

[HI] fgetc() और fputc() के विपरीत (जो EOF लौटाते हैं), fgets() एक char* पॉइंटर फंक्शन है और EOF या त्रुटि पर NULL लौटाता है।

Q12. Which file mode allows both reading and writing while preserving existing content and starting at byte 0?

(कौन-सा फाइल मोड पुराने डेटा को सुरक्षित रखते हुए बाइट 0 से पढ़ने और लिखने दोनों की अनुमति देता है?)

(A) "r+"

(B) "a"

(C) "w+"

(D) "r"

Correct Answer: (A)

[EN] "r+" opens an existing file for update (reading and writing) without truncating it, positioned initially at the start.

[HI] "r+" पहले से मौजूद फाइल को बिना मिटाए शुरुआत से पढ़ने और लिखने (अपडेट) दोनों के लिए खोलता है।

Q13. In a 10-character file line "Hello\n", how many characters does fgets(buf, 50, fp) store before '\0'?

("Hello\n" वाली लाइन पढ़ने पर fgets(buf, 50, fp) नल कैरेक्टर '\0' से पहले कितने कैरेक्टर स्टोर करेगा?)

(A) 7 characters

(B) 50 characters

(C) 6 characters ('H','e','l','l','o','\n')

(D) 5 characters ('H','e','l','l','o')

Correct Answer: (C)

[EN] fgets() stops right after reading '\n' and keeps that '\n' inside buf before appending '\0'.

[HI] fgets() '\n' पढ़ने के तुरंत बाद रुकता है और '\0' जोड़ने से पहले '\n' को बफर में रखता है।

Q14. What is the return value of fprintf(fp, "ID=%d", 42) when the write succeeds?

(लिखने के सफल होने पर fprintf(fp, "ID=%d", 42) क्या लौटाएगा?)

(A) 0

(B) 1

(C) 5

(D) 42

Correct Answer: (C)

[EN] The formatted string "ID=42" has 5 characters, and fprintf() returns the count of characters transmitted.

[HI] फॉर्मेटेड स्ट्रिंग "ID=42" में 5 कैरेक्टर हैं, और fprintf() सफलतापूर्वक लिखे गए कैरेक्टर्स की संख्या (5) लौटाता है।

Q15. Which file mode forces every write operation to go to the current end of the file, creating the file if absent?

(कौन-सा फाइल मोड हर राइट ऑपरेशन को फाइल के वर्तमान अंत में भेजता है और फाइल न होने पर नई बना देता है?)

(A) "r"

(B) "r+"

(C) "a"

(D) "w"

Correct Answer: (C)

[EN] Append mode "a" creates the file if needed and always writes at the end of the file.

[HI] अपेंड मोड "a" फाइल न होने पर उसे बनाता है और हमेशा फाइल के अंत में डेटा जोड़ता है।

Q16. Which of the following statements about standard C file I/O functions is NOT true?

(मानक C फाइल I/O फंक्शन्स के बारे में निम्नलिखित में से कौन-सा कथन सत्य नहीं है?)

(A) fscanf() skips leading whitespace for numeric specifiers like %d

(B) fgets() guarantees null-termination when it succeeds

(C) fclose() flushes buffered output before closing the stream

(D) fputs() automatically writes a trailing newline just like puts()

Correct Answer: (D)

[EN] fputs() writes only the characters in the provided string and does NOT append a newline, whereas puts() appends '\n'.

[HI] fputs() केवल दी गई स्ट्रिंग के कैरेक्टर लिखता है और न्यूलाइन नहीं जोड़ता, जबकि puts() स्वचालित रूप से '\n' जोड़ता है।

Q17. Within File Input/Output Functions: fgetc, fputc, fgets, fputs, fprintf, which function directly maps to: "Reads 1 byte as int; returns char or EOF"?

(File Input/Output Functions: fgetc, fputc, fgets, fputs, fprintf में कौन सा Function सीधे "Reads 1 byte as int; returns char or EOF" से संबंधित है?)

(A) fprintf(fp, fmt, ...)

(B) fputs(s, fp)

(C) fgets(s, n, fp)

(D) fgetc(fp)

Correct Answer: (D)

[EN] In File Input/Output Functions: fgetc, fputc, fgets, fputs, fprintf, 'fgetc(fp)' handles 'Reads 1 byte as int; returns char or EOF' (Must store in int, not char, to catch EOF (-1)).

[HI] File Input/Output Functions: fgetc, fputc, fgets, fputs, fprintf में 'fgetc(fp)' का कार्य/विवरण 'Reads 1 byte as int; returns char or EOF' (Must store in int, not char, to catch EOF (-1)) है।

Q18. Which option accurately describes 'fgets(s, n, fp)' in File Input/Output Functions: fgetc, fputc, fgets, fputs, fprintf?

(File Input/Output Functions: fgetc, fputc, fgets, fputs, fprintf के संदर्भ में 'fgets(s, n, fp)' की सही विशेषता कौन सी है?)

(A) Reads 1 byte as int; returns char or EOF

(B) Writes formatted text; returns char count

(C) Writes string; returns non-negative or EOF

(D) Reads up to n-1 chars; returns s or NULL

Correct Answer: (D)

[EN] 'fgets(s, n, fp)' provides 'Reads up to n-1 chars; returns s or NULL' — key point: Retains '\n' if read and appends '\0'.

[HI] 'fgets(s, n, fp)' का मुख्य विवरण 'Reads up to n-1 chars; returns s or NULL' है (Retains '\n' if read and appends '\0')।

Q19. In File Input/Output Functions: fgetc, fputc, fgets, fputs, fprintf, identify the correct parameter for the specification: "Writes string; returns non-negative or EOF".

(File Input/Output Functions: fgetc, fputc, fgets, fputs, fprintf में "Writes string; returns non-negative or EOF" विवरण किस विकल्प के लिए सही है?)

(A) fputs(s, fp)

(B) fgets(s, n, fp)

(C) fprintf(fp, fmt, ...)

(D) fgetc(fp)

Correct Answer: (A)

[EN] 'fputs(s, fp)' corresponds to 'Writes string; returns non-negative or EOF' (Does NOT append automatic newline like puts()).

[HI] 'fputs(s, fp)' का संबंध 'Writes string; returns non-negative or EOF' (Does NOT append automatic newline like puts()) से है।

Q20. Considering File Input/Output Functions: fgetc, fputc, fgets, fputs, fprintf, what key behavior defines 'fprintf(fp, fmt, ...)'?

(File Input/Output Functions: fgetc, fputc, fgets, fputs, fprintf में 'fprintf(fp, fmt, ...)' की मुख्य भूमिका या मान क्या है?)

(A) Writes string; returns non-negative or EOF

(B) Reads 1 byte as int; returns char or EOF

(C) Reads up to n-1 chars; returns s or NULL

(D) Writes formatted text; returns char count

Correct Answer: (D)

[EN] 'fprintf(fp, fmt, ...)' represents 'Writes formatted text; returns char count' (Returns negative value if stream write fails).

[HI] 'fprintf(fp, fmt, ...)' का अर्थ/मान 'Writes formatted text; returns char count' है (Returns negative value if stream write fails)।

File Input/Output Functions: fgetc, fputc, fgets, fputs, fprintf — Exam FAQs

Q1: Why does fgets() include '\n' in the buffer while gets() stripped it?

fgets() बफर में '\n' क्यों रखता है जबकि पुराना gets() उसे हटा देता था?

[EN] Keeping '\n' lets your code detect whether the entire line fit inside the buffer or was truncated because the buffer filled up before the end of the line.

[HI] '\n' को सुरक्षित रखने से प्रोग्राम यह पता लगा सकता है कि पूरी लाइन बफर में आ गई है या बफर भर जाने के कारण लाइन बीच में कट गई है।

Q2: What happens if you forget to call fclose(fp) before a program exits?

यदि प्रोग्राम समाप्त होने से पहले fclose(fp) कॉल करना भूल जाएं तो क्या हो सकता है?

[EN] On normal return from main() or exit(), C flushes open streams, but abnormal crashes (_exit/abort) discard buffered writes, and long-running programs leak OS file descriptors until fopen() fails.

[HI] सामान्य exit पर C स्ट्रीम्स फ्लश कर देता है, लेकिन क्रैश होने पर बफर्ड डेटा नष्ट हो सकता है और लंबे समय तक चलने वाले प्रोग्राम में फाइल डिस्क्रिप्टर्स लीक होकर fopen() विफल कर सकते हैं।

Q3: Can stdout and stdin be passed directly to fputs() and fgets()?

क्या stdout और stdin को सीधे fputs() और fgets() में पास किया जा सकता है?

[EN] Yes, stdin, stdout, and stderr are standard FILE* pointers defined in <stdio.h>, so fgets(buf, n, stdin) and fputs(buf, stdout) are completely valid.

[HI] हाँ, stdin, stdout और stderr <stdio.h> में परिभाषित मानक FILE* पॉइंटर्स हैं, इसलिए fgets(buf, n, stdin) और fputs(buf, stdout) पूरी तरह वैध हैं।

Related Posts

  • Loading related posts...

Post a Comment

Search Topic Notes & 20 MCQs (Hindi / English)