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⚡

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...

How to Create Studio Ghibli-Style AI Images on ChatGPT for Free

How to Create Studio Ghibli-Style AI Images on ChatGPT for Free AI-generated art is making waves across the internet, captivating audiences with stunning, ethereal visuals inspired by the iconic animation style of Studio Ghibli . These AI-crafted images, from dreamy landscapes to expressive characters, reflect the timeless magic of Hayao Miyazaki ’s beloved films such as Spirited Away , My Neighbor Totoro , and Howl’s Moving Castle . Thanks to recent advancements in AI technology, particularly OpenAI ’s latest ChatGPT update, users can now create their own Studio Ghibli-inspired illustrations effortlessly by entering simple text prompts. This exciting feature is transforming digital art creation and making it accessible to both professionals and beginners. In this article, we’ll guide you through creating Ghibli-style AI images using ChatGPT and explore free alternatives for users who don’t yet have access to this feature. Ghibli AI generator free Step-by-Step Guide: How to Crea...

Quiz tells you what type of wife you want

What Type of Wife are You Looking For? Attend this quiz and know your wife expections Quiz reveals type of wife you expect, lets answer carefully... Personality Questions: 1. What type of personality are you looking for in a wife? Quiet and reserved Outgoing and social Intelligent and witty 2. What type of sense of humor are you looking for in a wife? Dry and sarcastic Witty and clever Playful and silly 3. What type of interests are you looking for in a wife? Intellectual and educational Creative and artistic Athletic and outdoorsy Values Questions: 4. What type of family values are you looking for in a wife? Traditional and conservative Open-minded and progressive Balanced and equal 5. What type of political views...

Policy vs Innovation Matrix - India

Policy vs Innovation Matrix Policy vs Innovation Matrix that shows the structural difference between policy intent and actual innovation output — and how India’s model is transforming to match global innovation systems . From Paper Policies to Product Power 🧱 Traditional Indian Model (Old System) Policy Layer Reality Innovation Outcome Policy Vision Strong national policies Vision without execution pipelines Funding Govt-dominated funding Limited capital availability Risk Culture Risk-averse systems No deep-tech experimentation Research Academic publications Low commercialization Industry Role Minimal R&D involvement Weak private innovation Infrastructure Limited labs & compute Research bottlenecks Talent High-quality brains Brain drain Commercialisation Weak tech transfer Research stays in journals Scale Fragmented schemes No national scale impact Speed Slow approvals Innovation delays Result: ➡ Policy existed ➡ Innovation did not scale ➡ Research stayed inside institutions ...

Linked List Data Structure

Linked List Prerequisites for Linked List Definition of linkedlist Important points of Linked List Types of Linked List Basic Operations performed on Linked List Difference Between Linked List and Arrays Drawbacks of Linked List Applications of Linked List In real world Singly Linked List in C Doubly Linked List in C Singly Circular Linked List in C Doubly Circular Linked Listist in C Add node in Singly Linked List Display Data of Linked List Deletion of a node from linked list Prerequisites for Linked List pointer concept (*ptr) Address Operator (&ptr) Pointer A pointer is a variable which stores the address of another variable. By using a pointer we can directly access the memory address of the variable. Like any variable or constant, you must declare a pointer before using it to store any variable address. The general form of a pointer variable declaration is type *variable-name; Here, type is the pointer...

India won T20 World Cup 2024

India Triumphs in T20 World Cup! Cricket fans around the world witnessed a nail-biting finish as India edged past South Africa by 7 runs to clinch the ICC Men's T20 World Cup 2024. The historic win at Kensington Oval in Barbados ended India's 13-year trophy drought in ICC tournaments. India set a challenging target of 176 runs, with valuable contributions from their batsmen. South Africa fought valiantly, but fell short in their chase, finishing at 169 runs. This victory marks a momentous occasion for Indian cricket, solidifying their dominance in the T20 format.