Skip to content
  • Facebook
GeekCer Logo

GeekCer

The geek's Coding education and Review centre

  • Home
  • Tutorials
    • Java
    • Servlet
    • JSP
    • Python
    • C Tutorial
    • Spring
    • Spring Boot
    • MongoDB
    • Hibernate
    • Data Structure
  • General Knowledge
  • Biography
  • Grammar
  • Festival (त्योहार)
  • Interview
  • Differences
  • Important
  • Toggle search form

Home » C Language » String Array in C | What is an array of string | String Functions

  • Stack Vs Heap in Java
    Stack Vs Heap in Java | Memory Allocation Section in Java Differences
  • Digital Marketing in Hindi (डिजिटल मार्केटिंग क्या है?)
    Digital Marketing in Hindi (डिजिटल मार्केटिंग क्या है?) | डिजिटल मार्केटिंग का महत्व Important
  • Java Comments
    Java Comments : Types of java comments, Syntax & Examples Java
  • Pointers in C Programming, Definition, Types & Example
    Pointers in C Programming, Definition, Types & Example C Language
  • Diwali The Festival of Lights
    Diwali The Festival of Lights Festival
  • Python Variable and Python Datatype
    Python Variable and Python Datatype Python
  • What is Tense in Hindi (काल क्या है)?
    What is Tense in Hindi (काल क्या है)? Grammar
  • Difference between StringBuffer and StringBuilder
    Difference between StringBuffer and StringBuilder Differences

String Array in C | What is an array of string | String Functions

Posted on November 19, 2021April 19, 2022 By admin No Comments on String Array in C | What is an array of string | String Functions
String Array in C | What is an array of string | String Functions

String is a sequence of characters that ends with the null character, which is a special character (“\0”). The term “string” refers to a collection of characters. In the C programming language, the string array is a popular two-dimensional array. When we talk about an array of characters, we’re talking about something similar to a string array. We use a null character at the end of each string.

Table of Contents

  • Syntax for a String array
  • Initializing a String array
  • Functions of String in C
    • strcat()
    • strlen()
    • strrev()
    • strcpy()
    • strcmp()
    • strupr()
    • strlwr()
  • Pass string as parameters in C

Syntax for a String array


char_datatype array_name[No.of strings][size of each string];

Initializing a String array


char name[3][10] = {"It","is","String"};

Functions of String in C

FunctionsDescription
strcat()It’s used to concatenate (join) two strings together.
strlen()It’s used to display how long a string is.
strrev()It’s used to reverse a string.
strcpy()One string is copied into another.
strcmp()It’s used to do a comparison between two strings.
strupr()The strupr() method converts a string to uppercase.
strlwr() The strlwr () method converts a string to lowercase.

strcat()

Strings str1 and str2 are concatenated in this function, and string str2 is added to the end of string str1.


Syntax:
strcat(str1, str2); 
Example:
strcat("Soft","ware");

Output:
Software

strlen()

By using strlen() method we find the length of the string. Here length means the number of characters present in the string.


Syntax:
strlen(str);
Example:
strlen("GeekCer")

strrev()


Syntax:
strrev(str);
Example:
strrev("GeekCer")

strcpy()

The strcpy() method copies a string’s contents into another.


Syntax:
strcpy(str1,str2); /* Copies str2 into str1*/
Example:
strcpy(str,"GeekCer"); /* Copies "GeekCer" to str*/

strcmp()

The strcmp() is a function that compares two strings str1 and str2 to see if they are identical or dissimilar. Internally, two strings are compared character by character.

Strcmp() returns 0 if the two strings are equal. If they aren’t the same, the result returned is the numerical difference between the ASCII values of the first pair of characters.


Syntax:
strcmp(str1, str2); 
Example:
strcmp("Soft","ware");

strupr()

The strupr() function converts the case of the specified string to upper case. For example, If you specify “geekcer” this method will change it to “GEEKCER.”


Syntax:
strupr(str);
Example:
strupr("GeekCer")

strlwr()

The strlwr() function converts the case of the string to lower case. For example, If you specify “GEEKCER” this method will change it to “geekcer”.


Syntax:
strlwr(str);
Example:
strlwr("GeekCer")

Click here to learn basics C programming

Pass string as parameters in C

The countStr() is a function in this program that counts the number of characters in a string. We’re sending char array as a method argument since string is just a character array.


#include<stdio.h>

int countStr(char str[]) {
  int i = 0;
  while (str[i] != '\0') {
    i++;
  }
  return i;
}

int main() {
  char str[18] = "GeekCer Education";
  int count = 0;
  count = countStr(str);
  printf("Characters are : %d", count);
  return 0;
}


Share this:

  • Click to share on Facebook (Opens in new window)
  • Click to share on WhatsApp (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • More
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Pinterest (Opens in new window)

Also Read

C Language Tags:How do I declare an array of strings in C?, Passing char to function in c, String array in c programming examples, String function call in C, String in C, What are string arrays?, What are the string functions in C?, What is string array in C?, What is string in C language?

Post navigation

Previous Post: Array in C programming | Character Array in C
Next Post: Function in C Language | Recursive function with example

More Related Articles

Programming with C Language Tutorial Programming with C Language Tutorial C Language
Structure in C program with example | Nested structure in C Structure in C program with example | Nested structure in C C Language
Pointers in C Programming, Definition, Types & Example Pointers in C Programming, Definition, Types & Example C Language
Storage classes in C with examples (auto, extern, static, register) Storage classes in C with examples (auto, extern, register, static) C Language
Constants and Operators in C Language Constants and Operators in C Language C Language
Array in C programming | Character Array in C Array in C programming | Character Array in C C Language

Related Posts

  • Programming with C Language Tutorial
    Programming with C Language Tutorial C Language
  • Structure in C program with example | Nested structure in C
    Structure in C program with example | Nested structure in C C Language
  • Pointers in C Programming, Definition, Types & Example
    Pointers in C Programming, Definition, Types & Example C Language
  • Storage classes in C with examples (auto, extern, static, register)
    Storage classes in C with examples (auto, extern, register, static) C Language
  • Constants and Operators in C Language
    Constants and Operators in C Language C Language
  • Array in C programming | Character Array in C
    Array in C programming | Character Array in C C Language

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • C Home
  • Constants and Operators
  • Statements in C Language
  • Array in C
  • String Array in C
  • Functions in C
  • Pointers in C
  • Structure in C
  • Storage Classes
  • File Handling in C
  • Top C Programs

Recent Posts

  • Structured Vs Unstructured Data in Hindi | Key Difference
  • Jhansi Ki Rani Lakshmi Bai History, Story, Information in Hindi
  • Elon musk Hindi : एलन मस्क हिंदी में, Autobiography,  Net Worth
  • World Environment Day in Hindi : Objective, Importance, Theme
  • Thomas Edison Biography in Hindi – थॉमस एडिसन जीवनी
  • International Nurses Day in Hindi | नर्स दिवस क्यों मनाते हैं?
  • Fork/Join Framework in Java | RecursiveTask, RecursiveAction
  • DBMS in Hindi | DBMS क्या है? | DBMS की विशेषताएं और प्रकार
  • Stack Vs Heap in Java
    Stack Vs Heap in Java | Memory Allocation Section in Java Differences
  • Digital Marketing in Hindi (डिजिटल मार्केटिंग क्या है?)
    Digital Marketing in Hindi (डिजिटल मार्केटिंग क्या है?) | डिजिटल मार्केटिंग का महत्व Important
  • Java Comments
    Java Comments : Types of java comments, Syntax & Examples Java
  • Pointers in C Programming, Definition, Types & Example
    Pointers in C Programming, Definition, Types & Example C Language
  • Diwali The Festival of Lights
    Diwali The Festival of Lights Festival
  • Python Variable and Python Datatype
    Python Variable and Python Datatype Python
  • What is Tense in Hindi (काल क्या है)?
    What is Tense in Hindi (काल क्या है)? Grammar
  • Difference between StringBuffer and StringBuilder
    Difference between StringBuffer and StringBuilder Differences
  • Java Tutorial
  • Servlet Tutorial
  • JSP Tutorial
  • Maven Tutorial
  • HTML Tutorial
  • Programs
  • Hindi/English Grammar
  • Difference Between ... and ...
  • HR Interview
  • Important Articles

Write to Us:
geekcer.code@gmail.com

  • About Us
  • Privacy and Policy
  • Disclaimer
  • Contact Us
  • Sitemap

Copyright © GeekCer 2022 All Rights reserved