Question

ow do you check if a string starts with a certain character in c programing language?...

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?

Homework Answers

Answer #1

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");

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
C++ How do you get the first character of a string? The last character? How do...
C++ How do you get the first character of a string? The last character? How do you remove the first character? The last character?
C++: Write a function that receives a pointer to a character string consisting of only alphabets...
C++: Write a function that receives a pointer to a character string consisting of only alphabets a-z and returns the character with the maximum number of repetitions. If more than one-character repeats same number of times, return the character with smallest alphabetical order. For example, the string “Mississippi” has three repeated characters (i-4, s-4, p-2). Both ‘i’ and ‘s’ repeated 4 times but ‘i’ is alphabetically smaller hence the function should return ‘i’. Do not count repeated blanks, special characters,...
use repl.it intro to C-programing no advance code also put good comment that i can know...
use repl.it intro to C-programing no advance code also put good comment that i can know whats this code use for  thank you use repl.it intro to C-programing no advance code also put good comment that i can know whats this code use for  thank you program for a game of hangman. Store the word to be guessed as individual characters of an array called word. The player must guess the letters belonging to word. If the user enters a valid letter,...
Convert this C++ program exactly as you see it into x86 assembly language: // Use the...
Convert this C++ program exactly as you see it into x86 assembly language: // Use the Irvine library for the print function #include <iostream> // The string that needs to be printed char word[] = "Golf\0"; // Pointer to a specific character in the string char * character = word; //NOTE: This main() function is not portable outside of Visual Studio void main() { // Set up a LOOP - See the while loop's conditional expression below int ecx =...
Write a function to create a copy of a string with the prototype below. (C Language)...
Write a function to create a copy of a string with the prototype below. (C Language) char * strcpy (const char *); The function should dynamically allocate the necessary memory for the new string. You can do that with char * newstr = (char *) malloc(sizeof(char) * (strlen(str)+1)); assuming str is your input string. Think though how you would copy the characters of the string, and don't forget about the end of string character.
Write a program that accepts an input string from the user and converts it into an...
Write a program that accepts an input string from the user and converts it into an array of words using an array of pointers. Each pointer in the array should point to the location of the first letter of each word. Implement this conversion in a function str_to_word which returns an integer reflecting the number of words in the original string. To help isolate each word in the sentence, convert the spaces to NULL characters. You can assume the input...
For C++, how do I read through a file called "dictionary.txt" and see if the word...
For C++, how do I read through a file called "dictionary.txt" and see if the word user-inputted is in the file, but using cstring only and NOT string. For example, if the dictionary.txt is like Another ostentatious work extra dog camera hinder the output should look like this, Enter a word to be looked up in dictionary: cats cats is NOT in the dictionary. Enter a word to be looked up in dictionary: ostentatious ostentatious IS in the dictionary.
Specify and implement an ADT character string by using a linked chain of characters. Include typical...
Specify and implement an ADT character string by using a linked chain of characters. Include typical operations such as fi nding its length, appending one string to another, fi nding the index of the leftmost occurrence of a character in a string, and testing whether one string is a substring of another. Do not #include<string>...you are making something like a STL string. Also do not use an array or vector...the point is to practice linked lists. Remember the last character...
In C++ , given, string words = "OO/CC II/ZZ"; How do you make it so if...
In C++ , given, string words = "OO/CC II/ZZ"; How do you make it so if user inputs Z, you replace of the Z with ' '  and return words = "OO/CC II/Z "; and if the user inputs another Z then it returns words = "OO/CC II/ "; but if the user inputs Z for the third time, it makes the user re-enter another character and shows a retry message.
MIPS ASSEMBLY Have the user input a string and then be able to make changes to...
MIPS ASSEMBLY Have the user input a string and then be able to make changes to the characters that are in the string until they are ready to stop. We will need to read in several pieces of data from the user, including a string and multiple characters. You can set a maximum size for the user string, however, the specific size of the string can change and you can’t ask them how long the string is (see the sample...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT