We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 06ed0fb commit 0945258Copy full SHA for 0945258
058_length_of_last_word/Makefile
@@ -0,0 +1,2 @@
1
+all:
2
+ gcc -O2 -o test word_length.c
058_length_of_last_word/word_length.c
@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include <stdlib.h>
3
+
4
+int lengthOfLastWord(char *s)
5
+{
6
+ int len = 0;
7
+ while (*s != '\0') {
8
+ if (s[-1] == ' ' && s[0] != ' ') {
9
+ len = 1;
10
+ } else if (*s != ' ') {
11
+ len++;
12
+ }
13
+ s++;
14
15
+ return len;
16
+}
17
18
+int main(int argc, char **argv)
19
20
+ if (argc != 2) {
21
+ fprintf(stderr, "Usage: ./test word\n");
22
+ exit(-1);
23
24
25
+ printf("%d\n", lengthOfLastWord(argv[1]));
26
+ return 0;
27
0 commit comments