-
Notifications
You must be signed in to change notification settings - Fork 0
/
EnterName.c
54 lines (47 loc) · 899 Bytes
/
EnterName.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
Developer : Neeraj Kr. sharma
Q. program to Enter names of minimum size 10 characters and print it on the std output device.
Dry Run:
Input :
ramesh
dinesh
shyam
output:
ramesh
dinesh
shyam
Comment : I have used totally different approach for this.
*/
#include<stdio.h>
int main()
{
int i=0,c,limit=0;
char buffer[32];
printf("Enter names(press ctrl+z to exit):\n");
while((c=getchar())!=EOF)
{
limit++;
if(limit<=11){
if(c=='\n'){
buffer[i++]='\n';
limit=0;
}
else
buffer[i++]=c;
}
else
{
printf("Name greater than 10 characters is not allowed\n");
break;
}
}
buffer[i]='\0';
i=0;
printf("Following are the Entered Names:\n");
while(buffer[i]!='\0')
{
putchar(buffer[i]);
i++;
}
return 0;
}