Java Introduction
Java Introduction
“ARUN” ,’a’;
Strings in c are nothing but an
array of characters terminated
by a null character
Strings are decalred in the
same manner as that of arrays
Declare an string
Char str[6]=”Hello”; last
character in a string will be
null charater that shows the
end of the string
Declaration of string
Char *name;
Initialization of strings
Char str[]=”Hello”;
Char str[50]=”Hello”;
Chat str[]={‘H’,’e’,’l’,’l’,’o’,’\0’};
Char *name=”Hello”;
Reading from the user
%s
Example 2 When you use scanf to read a string any #include <stdio.h>
white space character will be considered as int main()
termination it will stop further reading in case of {
scanf char name[100];
Now how to read a line of text using scanf function printf("Enter the name\n");
scanf("%[^\n]",name);
printf("%s\n",name);
return 0;
}
int main()
{
char str[100],ch;
int i=0;
printf("Input a string\n");
while(ch!='\n'){
ch=getchar();
str[i]=ch;
i++;
}
str[i]='\0';
printf("String read is : %s",str);
return 0;
}