Data Structures Using C, 2e Reema Thareja
Data Structures Using C, 2e Reema Thareja
Data Structures Using C, 2e Reema Thareja
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++;
string.
Note that even blank spaces are counted as characters in the string.
• 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.
© Oxford University Press 2014. All rights reserved.
Arrays of Strings
Let us see the memory representation of an array of strings.
R A M ‘\0’
Name[0]
M O H A N ‘\0’
Name[1]
S H Y A M ‘\0’
Name[2]
H A R I ‘\0]
Name[3]
Name[4] G O P A L ‘\0’
• Instead of using the while loop, we could have straight away used