Strings
Strings
C, 2e
Reema Thareja
Strings
char str[size];
printf(“%s”, str);
• str can be displayed by writing
puts(str);
i=0;
while(str[i] != '\0’)
{ putchar(str[i]);
i++;
• For example, LENGTH(“C PROGRAMMING IS FUN”) will return 20. Note that even blank spaces
• Here, the first index will specify how many strings are needed and the second index
specifies the length of every individual string. So we allocate space for 20 names
where each name can be maximum 30 characters long.
R A M ‘\0’
Name[0]
M O H A N ‘\0’
Name[1]
S H Y A M ‘\0’
Name[2]
Name[3] H A R I ‘\0]
Name[4] G O P A L ‘\0’
• Instead of using the while loop, we could have straight away used the puts() function, like
puts(pstr);