Character Strings in C

In the C programming language when we talk about a string constant or a string literal what that means is that it is a sequence of characters or symbols between a pair of double quotes " " . Anything between the quotes is interpreted by the compiler as a string. C doesn’t have any special operators in the language for processing strings but the standard library does provide an extensive number of different functions that can be performed on strings. Before we look at those functions we first need to define a string within C, to declare a string in C you have to simply use the char type followed by the name you want to give your string and then brackets after the name to indicate the size of the string. For example the syntax to simply declare the string would look like this :

char myString[20];
char word[] = {'H', 'e', 'l', 'l', 'o', '!'};
char word[6] = {"Hello!"};
printf("The word is: %s", word);
char input[10];
printf("Enter your name: ");
scanf("%s", input);
#include <stdio.h>
#include <string.h>
int main() {
char myString[] = "my string";
printf("The length of this string is: %d", strlen(myString)); return 0;
}
char myString[] = "The puppy ate it's food"  // The string to search
char lookFor = 'a'; // The character we are searching for
char *pLookFor = NULL; // Pointer initialized
pLookFor = strchr(myString, lookFor); // Stores address of 'lookFor' in the 'pLookFor' pointer

Full stack web developer with experience in Ruby on Rails, JavaScript, React and Redux and learning more!