224k views
2 votes
Using C, Write a program that reads a series of strings from standard input and prints only those strings beginning with the letter 'b'.

1 Answer

3 votes

Step-by-step explanation:

/Header file section

#include <stdio.h>

//Program begins with a main function

int main()

{

//Declare variables

char letters[100][20];

int i, num;

//Prompt and read the input from the user

printf("Enter how many series of strings are you entered:");

scanf("%d", &num);

printf("Enter %d strings:\\", num);

for (i = 0; i<num; i++)

scanf("%s", letters[i]);

//Display those string beginning with letter 'b'

printf("\\The strings are beginning with the letter \"b\":\\");

for (i = 0; i<num; i++)

{

//Find start letter is 'b' by using ASCIII

//(ASCII value of letter 'b' is 98)

if ((int)letters[i][0] == 98)

printf("%s\\", letters[i]);

}

return 0;

}