Skip to main content

Predefined String Library Functions

Following are the functions defined in the file string.h  

char *strcat(char *dest, char *src) 


Appends the string pointed to, by src to the end of the string pointed to by dest. 
 

char *strncat(char *dest, char *src, int n)


Appends the string pointed to, by src to the end of the string pointed to, by dest up to n characters long. 

char *strchr(char *str, char c)


Searches for the first occurrence of the character c in the string pointed to, by the argument str. 

int strcmp(char *str1, char *str2)


Compares the string pointed to, by str1 to the string pointed to by str2. 

int strncmp(char *str1, char *str2, int n)


Compares at most the first n bytes of str1 and str2. 

 char *strlwr(char *str)

 
Converts a string pointed to by str to lowercase.
  

char *strcpy(char *dest, char *src)


Copies the string pointed to, by src to dest. 

char *strncpy(char *dest, char *src, int n)


Copies up to n characters from the string pointed to, by src to dest.  

int strlen(char *str)


Computes the length of the string str up to but not including the terminating null character. 

char *strrchr(char *str, int c)


Searches for the last occurrence of the character c in the string pointed to by the argument str. 

char *strstr(char *str1, char *str2)


Finds the first occurrence of the entire string str2 which appears in the string str1. 

char *strupr(char *str) 


Converts a string pointed to by str to uppercase. 

char *strrev(char *str)


Reverses a string pointed to by str and returns reversed string.

int strcmpi(char *str1, char *str2)


Compares the string pointed to, by str1 to the string pointed to by str2 by ignoring case.  

char * strset(char *str, char ch)


Sets all characters in pointed to by str to the value of ch.
 

char * strnset(char *str, char ch, int n)


Sets the first n characters in pointed to by str to the value of ch. 

char * strtok(char *str1, char *str2)


searches str1 for tokens that are separated by delimiters specified in str2. Returns the pointers to the first character of first token in str1.

Program using string standard library functions 


#include<stdio.h> 
#include<string.h> 
main() 
char s1[20],s2[20]; 
int choice; 
do 
printf(“\n1: LENGTH OF STRING”); 
printf(“\n2: COPY STRING”); 
printf(“\n3: CONVERT TO UPPERCASE”); 
printf(“\n4: STRING CONCATENATION”); 
printf(“\n5: STRING COMPARE”); 
printf(“\n6: EXIT”); 
printf(“\n enter your choice”); 
scanf(“%d”,&choice); 
switch(choice) 
case 1: 
printf(“\n enter the string:”); 
gets(s1); 
printf(“\n The length is %d”,strlen(s1)); 
break; 
case 2: 
printf”(“\n Enter the string”); 
gets(s1); 
printf(“\n The copied string is %s”, strcpy(s2,s1)); 
break;
case 3: 
printf(“\n Enter the string”); 
gets(s1); 
printf(“\n The uppercase string is %s”,strupr(s1)); 
break; 
case 4: 
printf(“\n Enter the first string:”); 
gets(s1); 
printf(“\n Enter the second string:”); 
gets(s2); 
strcat(s1,s2); 
printf(“\n The concatenated string is %s”,s1); 
break; 
case 5: 
printf(“\n Enter the first string:”); 
gets(s1);printf(“\n Enter the second string:”); 
gets(s2); 
if (strcmp(s1,s2)==0) 
printf(“\n string are equal”); 
else 
if(strcmp(s1,s2)>0) 
printf(“s1 is greater than s2”); 
else 
printf(“s2 is greater than s1”); 
}while(choice!=6); 
}



Comments

Trending⚡

Happy birthday Hardik Pandya | In C programming

  Happy birthday Hardik Pandya . Now you are  28 years old. Great achievement you have. Let's we want to talk more about Hardik pandya. He is great cricketer. Pandya is awesome. In this Blog Post we are going to wish pandya " Happy birthday using C program". Let's tune with us till end. Now we have to wish pandya, so we are going to use printf () function printing message to pandya as " Happy birthday Hardik pandya Now you are 28 years old". Hardik pandya was born on 11 October in 1993. Now we are going to declare a variable called as current_age = 2021 - 1993. It calculate current age Of Hardik pandya. See the "Happy birthday pandya" using c programming. If you liked this Blog Post then don't forget to share with your computer science learning friends. Once again " Happy birthday Hardik Pandya sir". Read also Happy Rakshabandhan wish using C program Friendship day 2021 greetings in C

Understanding link.click() in JavaScript

Hey! Today i am going to share with you how to use link.click() function in javascript As a JavaScript developer, you may come across the need to programmatically click a link on a web page. The link.click() method is a commonly used way to do this, and it is important to understand how it works and when to use it. What is link.click()? link.click() is a method that can be used to simulate a click on a link element in JavaScript. It is typically used when you want to trigger a link click event programmatically, rather than requiring the user to physically click the link. How to use link.click() Using link.click() is relatively straightforward. First, you need to select the link element you want to click using a DOM selector such as getElementById() or querySelector(). Then, you can call the click() method on the link element to simulate a click. Here is an example: // select the link element const myLink = document.getElementById('my-link'); // simulate a cl...

Best course Recommendation of IT field in 2023

Recommend me best course 🎉50% Discount on registration today itself 🎉! Join Course Now In today's fast-paced digital age, staying updated with the latest technology trends is crucial for professionals looking to advance in their careers. With technology rapidly evolving, it is important to continuously upskill and gain new knowledge to stay relevant in the job market. In 2023, there are several courses in technology that are gaining popularity and are highly recommended for professionals seeking to enhance their skills in data science, analytics, and digital marketing. Data Science: Data science is an interdisciplinary field that combines statistical analysis, machine learning, and computer science to extract insights and knowledge from data. With the increasing amount of data available, data scientists are in high demand across various industries. The best courses in data science for 2023 are th...

Define a macro EQUALSTR which accepts two strings and compare equality of both string

Define a macro EQUALSTR which accepts two strings and compare equality of both string #include<stdio.h>  #include<string.h>  #define EQUALSTR(str1,str2) strcmp(str1,str2)?0:1  void main()  {  char str1[10],str2[10];  printf("\n Enter the two strings: ");  gets(str1);  gets(str2);  if(EQUALSTR(str1,str2))  printf("\n Strings are equal");  else  printf("\n Strings are not equal");  } Also Read C program to find largest of two numbers using Structure Predefined Macro program Macros vs Functions Preprocessor Syntax Task Performed by Preprocessor

check number is prime or odd or even using c program

Here is the c program to check if the user entered number is prime ,even and odd. These few lines of code solve three problems. In the above program we used integer type num variable for storing user entered numbers. Then we used the IF condition statement. That's all. IF condition for even number In the First IF statement we have a logic. If the number is divided by two then the reminder should be 0 then the number is an even number else not an even number. That simple logic is implemented in the first if statement. IF condition for odd number In the second IF statement we Implemented odd number logic. We identify odd numbers just by making little change in even number logic. If the number is divided by two then the reminder should not be a zero. Then the number is odd. That's simple logic used to identify whether a number is odd or not an odd number. IF condition for prime number In the third IF condition we implemented the logic of the prime number. In this IF ...

How to write programs in Bhai language

Bhai Language Bhai language is fun Programming language , with this language you can makes jokes in hindi. Bhai language written in typescript. It's very funny , easy and amazing language. Keywords of this language written in Hindi . Starting and ending of the program Start program with keyword " hi bhai " and end with " bye bhai ". It's compulsory to add this keyword before starting and end on the program. You write your programming logic inside this hi bhai and bye bhai . How to declare variables in Bhai language We use " bhai ye hai variable_name" keyword for declaring variables. In javascript we use var keyword for declaring variables but here you have to use " bhai ye hai " keyword. If you are declaring string then use " " double quotes. You can use Boolean variable like sahi and galat for true and false . How to print output in Bhai language You have to use " bol bhai " keyword for ...