अनफॉर्मेटेड इनपुट और आउटपुट फंक्शन्स उपयोगकर्ता द्वारा भेजे गए सिंगल इनपुट को पढ़ते हैं और कंसोल पर आउटपुट के रूप में मान प्रदर्शित करने की अनुमति देते हैं।
अनफॉर्मेटेड इनपुट फंक्शन्स
C प्रोग्रामिंग भाषा में अनफॉर्मेटेड इनपुट फंक्शन्स नीचे समझाए गए हैं:
getchar()
यह कीबोर्ड से एक कैरेक्टर पढ़ता है।
getchar() फंक्शन का सिंटैक्स निम्नानुसार है:
Variablename = getchar();
उदाहरण के लिए,
char a; a = getchar();
उदाहरण प्रोग्राम
निम्नलिखिश C प्रोग्राम getchar() फंक्शन के लिए है:
#include <stdio.h>
int main(){
char ch;
FILE *fp;
fp = fopen("file.txt", "w"); // open the file in write mode
printf("enter the text then press cntrl Z:\n");
while((ch = getchar()) != EOF){
putc(ch, fp);
}
fclose(fp);
fp = fopen("file.txt", "r");
printf("text on the file:\n");
while((ch = getc(fp)) != EOF){
if(fp){
char word[100];
while(fscanf(fp, "%s", word) != EOF){ // read words from file
printf("%s\n", word); // print each word on separate lines.
}
fclose(fp); // close file.
}else{
printf("file doesnot exist");
}
}
return 0;
}
आउटपुट
enter the text then press cntrl Z: This is an example program on getchar() ^Z text on the file: This is an example program on getchar()
gets()
यह कीबोर्ड से एक स्ट्रिंग पढ़ता है।
gets() फंक्शन का सिंटैक्स निम्नानुसार है:
gets(variablename);
उदाहरण
#include <stdio.h>
#include <string.h>
main(){
char str[10];
printf("Enter your name: \n");
gets(str);
printf("Hello %s welcome to Tutorialspoint", str);
}
आउटपुट
Enter your name: Madhu Hello Madhu welcome to Tutorialspoint
अनफॉर्मेटेड आउटपुट फंक्शन्स
C प्रोग्रामिंग भाषा में अनफॉर्मेटेड आउटपुट फंक्शन्स निम्नानुसार हैं:
putchar()
यह मॉनिटर पर एक कैरेक्टर प्रदर्शित करता है।
putchar() फंक्शन का सिंटैक्स निम्नानुसार है:
putchar(variablename);
उदाहरण के लिए,
putchar('a');
puts()
यह मॉनिटर पर एक स्ट्रिंग प्रदर्शित करता है।
puts() फंक्शन का सिंटैक्स निम्नानुसार है:
puts(variablename);
उदाहरण के लिए,
puts("tutorial");
नमूना प्रोग्राम
निम्नलिखित C प्रोग्राम putc और getc फंक्शन्स के लिए है:
#include <stdio.h>
int main(){
char ch;
FILE *fp;
fp = fopen("std1.txt", "w");
printf("enter the text.press cntrl Z:\n");
while((ch = getchar()) != EOF){
putc(ch, fp);
}
fclose(fp);
fp = fopen("std1.txt", "r");
printf("text on the file:\n");
while((ch = getc(fp)) != EOF){
putchar(ch);
}
fclose(fp);
return 0;
}
आउटपुट
enter the text.press cntrl Z: This is an example program on putchar() ^Z text on the file: This is an example program on putchar()