String functions of C program

String positions of char in C Strings are commonly used data types in C . Strings are also known as Character array as they consists of group of chars.
char name[]={'p','l','u','s','2','n','e','t','\0'};

Declaring a string in C

First position of the string starts with 0. While declaring a string we can specify the number of chars to be used or reserved in memory.

Null char at the end

When we declare a string, C adds one null character ( \0 ) at the end. So we can check for this null character to identify the end of the string.
char name[10]="plus2net";
We can insert one null char ( \0 ) to terminate the string.
char name[10]="plus2net";
printf("%s",name);  // plu
We can check for this null character to identify the end of the string.
char name[]="plus2net";
int i=0;
printf("%c ",name[i]);
p l u s 2 n e t
strcat()Append string
strncat()Append part of the string
strcpy()Copy string
strncpy()Copy part of a string
strlen() Length of a string
strrev() String Reverse
strlwr() Upper to lowercase letter
strupr() Lower to Uppercase letter
strchr() Searching for first occurrence of chracter
strrchr() Searching for last occurrence of chracter
strcmp() Case sensitive string comparison
strcmpi() Case insensitive string comparison
strstr() Searching for string
strset() Setting all chars of the string
strnset() Setting part of the chars of the string
strdup() Duplicating string
strtok() Parses a string into sequence of tokens
Basic string assignments

Sample Codes

Printing string vertically with total number of chars
#include <stdio.h>
int main(void){
int i;
char str[]="Welcome";

for ( i=0;str[i] != '\0';i++){
printf( "%c \n",str[i]);
printf("\n Total number of chars = %d",i);
return 0;

 Total number of chars = 7
C Tutorials

Post your comments , suggestion , error , requirements etc here

We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 All rights reserved worldwide Privacy Policy Disclaimer