Accepting a String
String is an array of characters with the last element as '0'.So whenver a character array is declared the size of the array should be one more than the actual size of the string so that it contains '0'.
/*
http://www.ProbCOMP.com
String is an array of characters with the last element as '\0'.
So whenver a character array is declared the size of the array should be one more than the actual size of the string so that it contains '\0'.
*/
#include<stdio.h>
void main()
{
char name[20],c;
int i=0;
printf("enter your name: ");
while(1)
{
c=getchar();
if(c=='\n')
break;
name[i]=c;
i++;
}
name[i]='\0';
printf("%s",name);
}
Download Program


