ow do you check if a string starts with a certain character in c programing language? For example if a user puts in a word like cake how od i check if that word starts with c?
In c language, the strings are stored as character arrrays , the first character is stored at index 0 of the given string name,
for example, the string name is word[20] of size 20 , the first character is at word[0].
It is compared as
if(word[0]=='c'
if the word starts with c, then the condition is true otherwise the condition is false
Example program
#include<stdio.h>
int main()
{
char word[ ]="cake";
if(word[0]=='c')
printf("The word begins with character c");
else
printf("The word does not begins with character c");
}
Get Answers For Free
Most questions answered within 1 hours.