Try the below codes
Program1
#include<stdio.h>
int main()
{
int i=2; //two times
while(i>0)
{
char ch[2];
scanf("%s",ch);
printf("%s\n",ch);
i--;
}
return 0;
}
output (loop never terminate and take and print any length of string)
wdefgfvcdswdfetgyhujik
wdefgfvcdswdfetgyhujik
nbvewsq
nbvewsq
hgbvfdw
hgbvfdw
hbgfvedw
hbgfvedw
gfvdcwsq
gfvdcwsq
.
.
.
output(loop terminates when it take the valid set of string)
a
a
b
b
program2
#include<stdio.h>
int main()
{
char ch[2];
scanf("%s",ch);
printf("%s\n",ch);
return 0;
}
output(How does it print and say Segmentation fault)
sxdfvghujiuytredwsazxacdfv
sxdfvghujiuytredwsazxacdfv
Segmentation fault