Skip to content

Commit fd6efe6

Browse files
committed
stringLength
1 parent 8edc4e8 commit fd6efe6

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

prog.10.2.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Function to count the number of characters in a string
2+
3+
#include <stdio.h>
4+
5+
int stringLength (const char string[])
6+
{
7+
int count = 0;
8+
9+
while ( string[count] != '\0' )
10+
++count;
11+
12+
return count;
13+
}
14+
15+
int main (void)
16+
{
17+
int stringLength (const char string[]);
18+
const char word1[] = { 'a', 's', 't', 'e', 'r', '\0' };
19+
const char word2[] = { 'a', 't', '\0' };
20+
const char word3[] = { 'a', 'w', 'e', '\0' };
21+
22+
printf ("%i %i %i\n", stringLength (word1),
23+
stringLength (word2), stringLength (word3));
24+
25+
return 0;
26+
}

0 commit comments

Comments
 (0)