C Programming Week9
C Programming Week9
1
14/10/17
2
14/10/17
SD, PSK, NSN, DK, TAG – CS&E, IIT M 15 SD, PSK, NSN, DK, TAG – CS&E, IIT M 16
/* Arrays of strings */ /* Check that we have enough space for both strings */
#include <stdio.h> if (sizeof str[0] < count1 + count2 + 1)
void main() { printf("\n Not enough space for both strings.");
char str[ ][40] = {"String in C”, "Another string in C”}; else { /* Copy 2nd string to first */
int i = count1, j = 0;
int count1 = 0; /* Length of first string */ while((str[0][i++] = str[1][j++]) != '\0');
int count2 = 0; /* Length of second string */ printf("\n%s", str[0]); /* Output combined string */
/* find the length of the strings */ }
while (str[0][count1] != '\0') count1++; /* 11 */ }
while (str[1][count2] != '\0') count2++; /* 19 */
SD, PSK, NSN, DK, TAG – CS&E, IIT M 17 SD, PSK, NSN, DK, TAG – CS&E, IIT M 18
3
14/10/17
4
14/10/17
SD, PSK, NSN, DK, TAG – CS&E, IIT M 25 SD, PSK, NSN, DK, TAG – CS&E, IIT M 26