-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a1815d2
commit 87ecb94
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <stdio.h> | ||
|
||
int lengthOfLastWord(char *s) | ||
{ | ||
int len = 0; | ||
while(*s != '\0') | ||
{ | ||
if(s[-1] == ' ' && s[0] != ' ') | ||
{ | ||
len = 1; | ||
} | ||
|
||
else if(*s != ' ') | ||
{ | ||
len++; | ||
} | ||
|
||
s++; | ||
} | ||
|
||
return len; | ||
} | ||
|
||
int main(void) | ||
{ | ||
char str[] = "Hello world"; | ||
int len = lengthOfLastWord(str); | ||
printf("%d\n",len); | ||
|
||
} |