learn:c/c++ getchar() , gets() ,putchar() और puts() function क्या होते है programming c in hindi part 7
getchar() , gets() ,putchar() और puts() function क्या होते है और इनका use कब होता है
programming c&c++ tutorial में आपका स्वागत है . इससे पिछली पोस्ट में
मैंने scanf() and printf() function के बारे में बताया था .
scanf() and printf() function क्या है in program c
और आज जो हम पड़ने जा रहे है वो input and output function से ही related है .
getchar():-
जब एक सिंगल character को input करना होता है तब getchar() का
उपयोग होता है .इस function को किसी argument की आवश्यकता नहीं होती है .
getchar() function का syntax
ch=getchar();
जहाँ ch एक variable नाम है जो की char type का declare होना चाहिए . तब हम
कुछ भी कीबोर्ड से input करेगे ch में स्टोर होगा परन्तु याद रखिये input एक
single character होना चाहिए .
gets() function:-
gets function का
उपयोग एक string को print करने के लिए किया जाता है .और gets() function प्रयोग white
spaces को शामिल करने वाले character की string को पड़ने में किया जाता है . ध्यान
रहे कि वह string जिसमे white spaces है उन्हें फॉर्मेट specifer के साथ scanf() function का प्रयोग करके नहीं पड़ा
जा सकता . इसका syntax ये है
gets(st);
जहाँ st एक character string variable है .
example
#include<stdio.h>
#include<conio.h>
Void main()
{
char str[33];
clrscr();
printf(“input a string”);
gets(st);
printf(“rhe entered string is : %s”,str);
getch();
}
आप इस program को अपने computer पर
run करा कर देख सकते हो .
putchar() function:-
यदि सिंगल character
को screen पर display कराना हो तो putchar() function का use करते है .
example
example
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf(“enter a character and press enter key”);
ch=getchar();
putchar(ch);
getch():
}
आप इस program को अपने computer पर बना कर देख सकते हो . जब यह program run
होगा तब computer input के लिए wait करेगा और जब आप एक सिंगल character input
करोगे तब putchar() function की मदद से input की गई value screen पर print हो
जाएगी .
puts() function:-
puts() function का उपयोग monitor screen पर character
string को display करने के लिए किया जाता है
Example
#include<stdio.h>
#include<conio.h>
void main()
{
char str[20];
clrscr();
printf(“input a string”):
scanf(“%s”,str);
puts(str);
getch();
}
जब यह program run होगा तब scanf() की help से user string input करेगा और
puts() function input की गई string को display पर print करा देगा .
तो अब आप getchar(), gets() , putchar() , puts() को अच्छी तरह से समझ गए होंगे और अगर आपको इस
पोस्ट से related कोई question पूछना हो तो comment के लिख कर पूछ सकते हो . इस
पोस्ट को facebook पर शेयर करने के लिए नीचे दिए गए facebook icon पर क्लिक करे .
No comments