Skip to content

Commit

Permalink
Merge pull request #51 from Shourya1911/patch-5
Browse files Browse the repository at this point in the history
Create firstletter.c
  • Loading branch information
Amit-S-Sahu authored Oct 26, 2024
2 parents ae21a00 + e2f84fc commit 175e253
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions shouryasinha/firstletter.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <stdio.h>
#include <string.h>

int printFirstLetters(const char *str) {
int length = strlen(str);

for (int i = 0; i < length; i++) {
// Checking if the first place is letter or space
if (i == 0 || (str[i - 1] == ' ' && str[i] != ' ')) {
printf("%c ", str[i]); // Printing first letter
}
}
}
int main() {
char str[100];

printf("Enter a sentence: ");
fgets(str, sizeof(str), stdin);

printf("First letters of each word: ");
printFirstLetters(str);
return 0;
}

0 comments on commit 175e253

Please sign in to comment.