4 Input Output
4 Input Output
#include<conio.h> void
main(){
char string[10];
printf("Enter Your Name:");
scanf("%s",string);
printf("My Name is %s",string);
getch();
}
16
• some versions of scanf() support the following
conversion specifications for strings:-
%[character]
– only characters specified within the brackets are
allowed in the input string.
%[^character]
– the character specified after the caret are not
allowed
17
#include<stdio.h>
#include<conio.h>
void main(){
char string[10];
printf("Enter Your Name in uppercase:");
scanf("%[A-Z]",string);
printf("Your Name is %s",string);
getch();
}
#include<stdio.h> 18
#include<conio.h>
void main(){
char string[10];
printf("Enter Your Name:");
scanf("%[^\n]",string);
printf("My Name is %s",string);
getch();
}
%[^\n] tells the compiler to read a string until a
newline character is entered
Reading Mixed Data 19
Types
• printf(“enter an integer, floating number,
gender and name:”);
scanf(“%d %f %c%s”,&i,&n1,&gender,&name);
Character_variable= getchar();
• puts()
– Used to display the string onto the
terminal
– General form:
puts(string_variable);
void 30
main()
{ char name[20];
clrscr();
printf("Enter your name:"); gets(name);
printf("Your Name is: "); puts(name);
getch();
}