Computer >> कंप्यूटर >  >> प्रोग्रामिंग >> C++

C . में tmpfile () फ़ंक्शन

फ़ंक्शन tmpfile() C में बाइनरी अपडेट मोड में एक अस्थायी फ़ाइल बनाता है। यह C प्रोग्राम की हेडर फ़ाइल में इनिशियलाइज़ होता है। यदि अस्थायी फ़ाइल नहीं बनाई जा सकती है तो यह हमेशा एक शून्य सूचक देता है। अस्थायी फ़ाइल प्रोग्राम की समाप्ति के तुरंत बाद स्वतः हटा दी जाती है।

सिंटैक्स

FILE *tmpfile(void)

रिटर्न वैल्यू

यदि फ़ाइल निर्माण सफल होता है, तो फ़ंक्शन बनाई गई अस्थायी फ़ाइल में एक स्ट्रीम पॉइंटर लौटाता है। यदि फ़ाइल नहीं बनाई जा सकती है, तो NULL पॉइंटर वापस आ जाता है।

एल्गोरिदम

Begin.
   Declare an array variable c[] to the character datatype and take a character data string.
   Initialize a integer variable i ← 0.
   Declare a newfile pointer to the FILE datatype.
   Call tmpfile() function to make newfile filepointer as temporary file.
   Call open() function to open “nfile.txt” to perform write operation using newfile file pointer.
   if (newfile == NULL) then
      print “Error in creating temporary file” .
      return 0.
   Print “Temporary file created successfully”.
   while (c[i] != '\0') do
      put all the data of c[] into the filepointer newfile.
      i++.
   Call fclose() function to close the file pointer.
   Call open() function to open “nfile.txt” to perform read operation using newfile file pointer.
   Call rewind() function to set the pointer at the beginning of the stream of the file pointer.
   while (!feof(newfile)) do
      call putchar() function to print all the data of file pointer newfile.
      Call fclose() function to close the file pointer.
End.

उदाहरण

#include <stdio.h>
int main() {
   char c[] = "Tutorials Point";
   int i = 0;
   FILE* newfile = tmpfile(); //make the file pointer as temporary file.
   newfile = fopen("nfile.txt", "w");
   if (newfile == NULL) {
      puts("Error in creating temporary file");
      return 0;
   }
   puts("Temporary file created successfully");
   while (c[i] != '\0') {
      fputc(c[i], newfile);
      i++;
   }
   fclose(newfile);
   newfile = fopen("nfile.txt", "r");
   rewind(newfile); //set the pointer at the beginning of the stream of the file pointer.
   while (!feof(newfile))
   putchar(fgetc(newfile));
   fclose(newfile); //closing the file pointer
}

आउटपुट

Temporary file created successfully
Tutorials Point

  1. PHP में फ़्रेड () फ़ंक्शन

    फ़्रेड () फ़ंक्शन एक खुली फ़ाइल से पढ़ता है। फ़्रेड () फ़ंक्शन फ़ाइल के अंत में रुक जाता है या जब यह निर्दिष्ट लंबाई तक पहुँच जाता है, जो भी पहले आता है। यह सफलता पर रीड स्ट्रिंग लौटाता है। विफल होने पर, यह FALSE लौटाता है। सिंटैक्स fread(file_pointer, length) पैरामीटर file_pointer - fopen() का उ

  1. PHP में fpassthru () फ़ंक्शन

    fpassthru() फ़ंक्शन एक खुली फ़ाइल से EOF तक पढ़ता है, और आउटपुट बफर को परिणाम लिखता है। यह फ़ाइल पॉइंटर से पढ़े गए वर्णों की संख्या देता है, अन्यथा यदि कोई त्रुटि होती है, तो यह FALSE लौटाता है। सिंटैक्स fpassthru(file_pointer): पैरामीटर file_pointer - फ़ाइल पॉइंटर को fopen() या fsockopen() द्वार

  1. PHP में fopen () फ़ंक्शन

    fopen() फ़ंक्शन एक फ़ाइल या URL खोलता है। यदि फ़ंक्शन विफल हो जाता है, तो यह FALSE और विफलता पर एक त्रुटि देता है। त्रुटि आउटपुट को छिपाने के लिए फ़ंक्शन नाम के सामने एक @ जोड़ें। सिंटैक्स fopen(file_path, mode, include_path, context) पैरामीटर file_path - फ़ाइल का पथ। मोड - फ़ाइल के लिए आपको क