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

  • जन्माष्टमी व्रत पूजा विस्तार से | दही हांडी | Krishna Janmashtami Puja
    जन्माष्टमी व्रत पूजा विस्तार से, दही हांडी: Krishna Janmashtami Puja Festival
  • Kapil Sharma Show, Comedy Show in Hindi
    Kapil Sharma Show, Comedy Show in Hindi Biography
  • Maharishi Valmiki in Hindi, Biography, Dacoit Ratnakar, Jayanti
    Maharishi Valmiki in Hindi, Biography, Dacoit Ratnakar, Jayanti Spiritual
  • Ohms law Definition, Formula, Statement
    Ohms law Definition, Formula, Statement | ओम का नियम Science
  • Farmers Day
    National Farmers Day in Hindi | राष्ट्रीय किसान दिवस पर निबंध | चौधरी चरण सिंह जयंती General Knowledge
  • Rabindranath Tagore Biography in Hindi, Poems, Birthday
    Rabindranath Tagore Biography in Hindi, Title of Gurudev Biography
  • Jhansi Ki Rani Lakshmi Bai History, Story, Information in Hindi
    Jhansi Ki Rani Lakshmi Bai History, Story, Information in Hindi Biography
  • Unicef day
    Unicef day is celebrated on December 11 | Speech on unicef day General Knowledge

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

Posted on November 19, 2021April 19, 2022 By GeekCer Education 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

Statements in C Language | Types of statements in C Language Statements in C Language | Types of statements in C Language C Language
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
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
Function in C Language | Recursive function with example Function in C Language | Recursive function with example 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
  • National Farmers Day in Hindi | राष्ट्रीय किसान दिवस पर निबंध | चौधरी चरण सिंह जयंती
  • Human rights day in Hindi: 10 दिसंबर ह्यूमन राइट्स डे
  • Unicef day is celebrated on December 11 | Speech on unicef day
  • Indian Navy Day: जल सेना दिवस कब और क्यों मनाया जाता है?
  • P V Sindhu Biography in Hindi, Badminton, State, Caste पी. वी. सिंधु जीवन परिचय, कहानी, राज्य, जाति
  • Draupadi Murmu Biography In Hindi | द्रौपदी मुर्मू की जीवनी
  • Similarities and difference between OSI and TCP/IP model
    OSI vs TCP/IP Model, Similarities and difference between OSI and TCP/IP model Networking
  • Network kya hai (नेटवर्क क्या है)
    Network kya hai (नेटवर्क क्या है) Networking
  • IPv4 Vs IPv6 | Difference between IPv4 and IPv6
    IPv4 Vs IPv6 | Difference between IPv4 and IPv6 Differences
  • TCP/IP Model, Full Form, Layers and their Functions
    TCP/IP Model, Full Form, Layers and their Functions Networking
  • OSI Model | 7 Layers of OSI Model in Computer network
    OSI Model | 7 Layers of OSI Model in Computer network, Functions Networking
  • Difference between Internet and Intranet
    Difference between Internet and Intranet Differences
  • Difference between TCP and UDP
    Difference between TCP and UDP | TCP vs UDP examples 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