SlideShare a Scribd company logo
Prepared by
Mohammed Sikander
Technical Lead
Cranes Software International Limited
 size_t strlen(const char *str);
mohammed.sikander@cranessoftware.com 2
size_t mystrlen(const char *str)
{
const char *end = str;
while( *end != ‘0’)
end++;
return end – str;
}
char * strcpy(char *dest, const char *src);
mohammed.sikander@cranessoftware.com 3
void mystrcpy(char *dest, const char *src)
{
while(1)
{
*dest = *src;
if(*dest == ‘0’)
return;
src++;
dest++;
}
}
char * strcpy(char *dest, const char *src);
mohammed.sikander@cranessoftware.com 4
void mystrcpy(char *dest, const char *src)
{
while((*dest++ = *src++))
{
}
}
mohammed.sikander@cranessoftware.com 5
void mystrncpy(char *dest, const char *src, size_t n)
{
for(int i = 0 ; i < n ; i++)
{
*dest = *src;
if(*dest == ‘0’)
return;
src++;
dest++;
}
}
int main( )
{
char str[20] = “KARNATAKA”;
char s1[20] = “ABCDEFGHIJKLMN”;
char s2[20] = “ABCDEFGHIJKLMN”;
mystrncpy(s1 , str ,5);
mystrncpy(s2 , str , 12);
printf(“s1 = %s n” , s1);
printf(“s2 = %s n” , s2);
}
int strcmp(const char *str1 , const char *str2);
mohammed.sikander@cranessoftware.com 6
int mystrcmp(const char *str1 , const char *str2)
{
while(1)
{
if(*str1 != *str2)
return *str1 - *str2;
if(*str1 == ‘0’)
return 0;
str1++;
str2++;
}
}
while(*str1 == *str2 && *str1 != ‘0’)
{
str1++;
str2++;
}
return *str1 - *str2;
int strncmp(const char *str1 , const char *str2,size_t n);
mohammed.sikander@cranessoftware.com 7
int mystrcmp(const char *str1 , const char *str2,size_t n)
{
for(int I = 0 ; i < n ; i++)
{
if(*str1 != *str2)
return *str1 - *str2;
if(*str1 == ‘0’)
return 0;
str1++;
str2++;
}
return 0;
}
int main( )
{
char str1[ ] = “ BANGALORE”;
char str2[ ] = “BANGKOK”;
int res;
res = mystrncmp(str1 , str2 , 3) ;
printf(“res = %d “ , res);
res = mystrncmp(str1 , str2 , 5) ;
printf(“res = %d “ , res);
}
int strcmpi(const char *str1 , const char *str2);
mohammed.sikander@cranessoftware.com 8
int mystrcmpi(const char *str1 , const char *str2)
{
while(1)
{
char x = toupper(*str1);
char y = toupper(*str2);
if(x != y)
return x - y;
if(*str1 == ‘0’)
return 0;
str1++;
str2++;
}
}
int main( )
{
char str1 [ ] = “ BANGALORE “;
char str2 [ ] = “bangalore”;
int res;
res = mystrcmpi( str1 , str2);
printf(“res = %d “ , res);
}
void mystrrev(char *startptr)
{
int len = strlen(startptr);
char *endptr = startptr + len - 1;
while(startptr < endptr)
{
myswap(startptr , endptr);
startptr++;
endptr--;
}
}
mohammed.sikander@cranessoftware.com 9
void myswap(char *a,char *b)
{
char temp = *a;
*a = *b;
*b = temp;
}
int main( )
{
char str[ ] = “ SIKANDER”;
printf(“str = %s” , str);
mystrrev(str);
printf(“n After Reverse n”);
printf(“str = %s” , str);
}
char *strchr(const char *str, char key);
char *mystrchr(const char *str , char key)
{
while(*str != ‘0’)
{
if(*str == key)
return str;
str++;
}
return NULL;
}
mohammed.sikander@cranessoftware.com 10
int main( )
{
char str[ ] = “BANGALORE”;
char *ptr;
ptr = mystrchr(str , ‘A’);
if(ptr == NULL)
printf(“Key Not found”);
else
printf(“Found at index “ , ptr – str);
ptr = mystrchr(str , ‘C’);
if(ptr == NULL)
printf(“Key Not found”);
else
printf(“Found at index “ , ptr – str);
}
char *strrchr(const char *str, char key);
char *mystrrchr(const char *start , char key)
{
int len = strlen(str);
char *end = start + len – 1;
while(end > start)
{
if(*end == key)
return end;
end--;
}
return NULL;
}
mohammed.sikander@cranessoftware.com 11
int main( )
{
char str[ ] = “BANGALORE”;
char *ptr;
ptr = mystrrchr(str , ‘A’);
if(ptr == NULL)
printf(“Key Not found”);
else
printf(“Found at index “ , ptr – str);
ptr = mystrrchr(str , ‘C’);
if(ptr == NULL)
printf(“Key Not found”);
else
printf(“Found at index “ , ptr – str);
}
char * mystrcat(char *dest , const char *src)
{
int len = strlen(dest);
mystrcpy(dest + len , src);
return dest;
}
mohammed.sikander@cranessoftware.com 12
char *mystrncat(char *dest , const char *src,size_t n)
{
int len = strlen(dest);
mystrncpy(dest + len , src , n );
}
char * mystrstr(char *str , char *key)
{
int len = strlen(key);
char *ptr;
while(1)
{
ptr = strchr(str , *key);
if(ptr == NULL)
return NULL;
int res = strncmp(ptr , key , len);
if(res != 0)
return ptr;
str = ptr + 1;
}
}
mohammed.sikander@cranessoftware.com 13
Main String :
BANGALORE
Sub String to Search :
GAL
GALA
LOT
Ad

More Related Content

What's hot (20)

Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
Vineeta Garg
 
Recursion in c
Recursion in cRecursion in c
Recursion in c
Saket Pathak
 
Function in c
Function in cFunction in c
Function in c
savitamhaske
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
Vraj Patel
 
C programming - String
C programming - StringC programming - String
C programming - String
Achyut Devkota
 
Structure of C++ - R.D.Sivakumar
Structure of C++ - R.D.SivakumarStructure of C++ - R.D.Sivakumar
Structure of C++ - R.D.Sivakumar
Sivakumar R D .
 
File handling in C++
File handling in C++File handling in C++
File handling in C++
Hitesh Kumar
 
Type casting in c programming
Type casting in c programmingType casting in c programming
Type casting in c programming
Rumman Ansari
 
Memory allocation in c
Memory allocation in cMemory allocation in c
Memory allocation in c
Prabhu Govind
 
Operator overloading C++
Operator overloading C++Operator overloading C++
Operator overloading C++
Lahiru Dilshan
 
07. Virtual Functions
07. Virtual Functions07. Virtual Functions
07. Virtual Functions
Haresh Jaiswal
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
Apurbo Datta
 
Pointers in C
Pointers in CPointers in C
Pointers in C
Kamal Acharya
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
kamal kotecha
 
Python lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce functionPython lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce function
ARVIND PANDE
 
6. static keyword
6. static keyword6. static keyword
6. static keyword
Indu Sharma Bhardwaj
 
design and analysis of algorithm Lab files
design and analysis of algorithm Lab filesdesign and analysis of algorithm Lab files
design and analysis of algorithm Lab files
Nitesh Dubey
 
Procedural programming
Procedural programmingProcedural programming
Procedural programming
Ankit92Chitnavis
 
Pointers, virtual function and polymorphism
Pointers, virtual function and polymorphismPointers, virtual function and polymorphism
Pointers, virtual function and polymorphism
lalithambiga kamaraj
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
rajveer_Pannu
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
Vineeta Garg
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
Vraj Patel
 
C programming - String
C programming - StringC programming - String
C programming - String
Achyut Devkota
 
Structure of C++ - R.D.Sivakumar
Structure of C++ - R.D.SivakumarStructure of C++ - R.D.Sivakumar
Structure of C++ - R.D.Sivakumar
Sivakumar R D .
 
File handling in C++
File handling in C++File handling in C++
File handling in C++
Hitesh Kumar
 
Type casting in c programming
Type casting in c programmingType casting in c programming
Type casting in c programming
Rumman Ansari
 
Memory allocation in c
Memory allocation in cMemory allocation in c
Memory allocation in c
Prabhu Govind
 
Operator overloading C++
Operator overloading C++Operator overloading C++
Operator overloading C++
Lahiru Dilshan
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
kamal kotecha
 
Python lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce functionPython lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce function
ARVIND PANDE
 
design and analysis of algorithm Lab files
design and analysis of algorithm Lab filesdesign and analysis of algorithm Lab files
design and analysis of algorithm Lab files
Nitesh Dubey
 
Pointers, virtual function and polymorphism
Pointers, virtual function and polymorphismPointers, virtual function and polymorphism
Pointers, virtual function and polymorphism
lalithambiga kamaraj
 

Viewers also liked (20)

Strings Functions in C Programming
Strings Functions in C ProgrammingStrings Functions in C Programming
Strings Functions in C Programming
DevoAjit Gupta
 
C string
C stringC string
C string
University of Potsdam
 
C programming string
C  programming stringC  programming string
C programming string
argusacademy
 
Strings
StringsStrings
Strings
Michael Gordon
 
Strings
StringsStrings
Strings
Nilesh Dalvi
 
String c
String cString c
String c
thirumalaikumar3
 
String functions in C
String functions in CString functions in C
String functions in C
baabtra.com - No. 1 supplier of quality freshers
 
Strings in C
Strings in CStrings in C
Strings in C
Kamal Acharya
 
Computer Programming- Lecture 5
Computer Programming- Lecture 5 Computer Programming- Lecture 5
Computer Programming- Lecture 5
Dr. Md. Shohel Sayeed
 
Implementation Of String Functions In C
Implementation Of String Functions In CImplementation Of String Functions In C
Implementation Of String Functions In C
Fazila Sadia
 
String function
String functionString function
String function
Jignesh Patel
 
String functions
String functionsString functions
String functions
Nikul Shah
 
Web Project Presentation - JoinPakForces
Web Project Presentation - JoinPakForcesWeb Project Presentation - JoinPakForces
Web Project Presentation - JoinPakForces
Wasif Altaf
 
C++ Preprocessor Directives
C++ Preprocessor DirectivesC++ Preprocessor Directives
C++ Preprocessor Directives
Wasif Altaf
 
Structures,pointers and strings in c Programming
Structures,pointers and strings in c ProgrammingStructures,pointers and strings in c Programming
Structures,pointers and strings in c Programming
baabtra.com - No. 1 supplier of quality freshers
 
Preprocessor
PreprocessorPreprocessor
Preprocessor
Learn By Watch
 
pre processor directives in C
pre processor directives in Cpre processor directives in C
pre processor directives in C
Sahithi Naraparaju
 
Structure in c
Structure in cStructure in c
Structure in c
baabtra.com - No. 1 supplier of quality freshers
 
Array in c language
Array in c languageArray in c language
Array in c language
home
 
Arrays
ArraysArrays
Arrays
archikabhatia
 
Ad

Similar to Implementation of c string functions (20)

Implementing string
Implementing stringImplementing string
Implementing string
mohamed sikander
 
week-6x
week-6xweek-6x
week-6x
KITE www.kitecolleges.com
 
Principals of Programming in CModule -5.pdfModule-4.pdf
Principals of Programming in CModule -5.pdfModule-4.pdfPrincipals of Programming in CModule -5.pdfModule-4.pdf
Principals of Programming in CModule -5.pdfModule-4.pdf
anilcsbs
 
compiler_yogesh lab manual graphic era hill university.docx
compiler_yogesh lab manual graphic era hill university.docxcompiler_yogesh lab manual graphic era hill university.docx
compiler_yogesh lab manual graphic era hill university.docx
chirag19saxena2001
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
manoj11manu
 
Arrays
ArraysArrays
Arrays
mohamed sikander
 
week-3x
week-3xweek-3x
week-3x
KITE www.kitecolleges.com
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statements
MomenMostafa
 
array, function, pointer, pattern matching
array, function, pointer, pattern matchingarray, function, pointer, pattern matching
array, function, pointer, pattern matching
Shakila Mahjabin
 
C Programming Language Part 11
C Programming Language Part 11C Programming Language Part 11
C Programming Language Part 11
Rumman Ansari
 
week-5x
week-5xweek-5x
week-5x
KITE www.kitecolleges.com
 
06 -working_with_strings
06  -working_with_strings06  -working_with_strings
06 -working_with_strings
Hector Garzo
 
Unitii string
Unitii stringUnitii string
Unitii string
Sowri Rajan
 
Pointer basics
Pointer basicsPointer basics
Pointer basics
Mohammed Sikander
 
c programming
c programmingc programming
c programming
Arun Umrao
 
Cryptography and network security record for cse .pdf
Cryptography and network security record for cse .pdfCryptography and network security record for cse .pdf
Cryptography and network security record for cse .pdf
Kirubaburi R
 
Find an LCS of X = and Y = Show the c and b table. Attach File .docx
  Find an LCS of X =  and Y =   Show the c and b table.  Attach File  .docx  Find an LCS of X =  and Y =   Show the c and b table.  Attach File  .docx
Find an LCS of X = and Y = Show the c and b table. Attach File .docx
Abdulrahman890100
 
Bind me if you can
Bind me if you canBind me if you can
Bind me if you can
Ovidiu Farauanu
 
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
GkhanGirgin3
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
ssuserd6b1fd
 
Principals of Programming in CModule -5.pdfModule-4.pdf
Principals of Programming in CModule -5.pdfModule-4.pdfPrincipals of Programming in CModule -5.pdfModule-4.pdf
Principals of Programming in CModule -5.pdfModule-4.pdf
anilcsbs
 
compiler_yogesh lab manual graphic era hill university.docx
compiler_yogesh lab manual graphic era hill university.docxcompiler_yogesh lab manual graphic era hill university.docx
compiler_yogesh lab manual graphic era hill university.docx
chirag19saxena2001
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statements
MomenMostafa
 
array, function, pointer, pattern matching
array, function, pointer, pattern matchingarray, function, pointer, pattern matching
array, function, pointer, pattern matching
Shakila Mahjabin
 
C Programming Language Part 11
C Programming Language Part 11C Programming Language Part 11
C Programming Language Part 11
Rumman Ansari
 
06 -working_with_strings
06  -working_with_strings06  -working_with_strings
06 -working_with_strings
Hector Garzo
 
Cryptography and network security record for cse .pdf
Cryptography and network security record for cse .pdfCryptography and network security record for cse .pdf
Cryptography and network security record for cse .pdf
Kirubaburi R
 
Find an LCS of X = and Y = Show the c and b table. Attach File .docx
  Find an LCS of X =  and Y =   Show the c and b table.  Attach File  .docx  Find an LCS of X =  and Y =   Show the c and b table.  Attach File  .docx
Find an LCS of X = and Y = Show the c and b table. Attach File .docx
Abdulrahman890100
 
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
GkhanGirgin3
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
ssuserd6b1fd
 
Ad

More from mohamed sikander (14)

C++ 11 range-based for loop
C++ 11   range-based for loopC++ 11   range-based for loop
C++ 11 range-based for loop
mohamed sikander
 
Pointer level 2
Pointer   level 2Pointer   level 2
Pointer level 2
mohamed sikander
 
Implementing stack
Implementing stackImplementing stack
Implementing stack
mohamed sikander
 
Understanding storage class using nm
Understanding storage class using nmUnderstanding storage class using nm
Understanding storage class using nm
mohamed sikander
 
Function basics
Function basicsFunction basics
Function basics
mohamed sikander
 
C++ Question on References and Function Overloading
C++ Question on References and Function OverloadingC++ Question on References and Function Overloading
C++ Question on References and Function Overloading
mohamed sikander
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
mohamed sikander
 
Cquestions
Cquestions Cquestions
Cquestions
mohamed sikander
 
Inheritance and polymorphism
Inheritance and polymorphismInheritance and polymorphism
Inheritance and polymorphism
mohamed sikander
 
C questions
C questionsC questions
C questions
mohamed sikander
 
Container adapters
Container adaptersContainer adapters
Container adapters
mohamed sikander
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
mohamed sikander
 
Stl algorithm-Basic types
Stl algorithm-Basic typesStl algorithm-Basic types
Stl algorithm-Basic types
mohamed sikander
 
Static and const members
Static and const membersStatic and const members
Static and const members
mohamed sikander
 

Recently uploaded (20)

Programs as Values - Write code and don't get lost
Programs as Values - Write code and don't get lostPrograms as Values - Write code and don't get lost
Programs as Values - Write code and don't get lost
Pierangelo Cecchetto
 
Digital Twins Software Service in Belfast
Digital Twins Software Service in BelfastDigital Twins Software Service in Belfast
Digital Twins Software Service in Belfast
julia smits
 
Download 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-ActivatedDownload 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-Activated
Web Designer
 
AEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural MeetingAEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural Meeting
jennaf3
 
Mobile Application Developer Dubai | Custom App Solutions by Ajath
Mobile Application Developer Dubai | Custom App Solutions by AjathMobile Application Developer Dubai | Custom App Solutions by Ajath
Mobile Application Developer Dubai | Custom App Solutions by Ajath
Ajath Infotech Technologies LLC
 
Robotic Process Automation (RPA) Software Development Services.pptx
Robotic Process Automation (RPA) Software Development Services.pptxRobotic Process Automation (RPA) Software Development Services.pptx
Robotic Process Automation (RPA) Software Development Services.pptx
julia smits
 
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studiesTroubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Tier1 app
 
Buy vs. Build: Unlocking the right path for your training tech
Buy vs. Build: Unlocking the right path for your training techBuy vs. Build: Unlocking the right path for your training tech
Buy vs. Build: Unlocking the right path for your training tech
Rustici Software
 
Memory Management and Leaks in Postgres from pgext.day 2025
Memory Management and Leaks in Postgres from pgext.day 2025Memory Management and Leaks in Postgres from pgext.day 2025
Memory Management and Leaks in Postgres from pgext.day 2025
Phil Eaton
 
Welcome to QA Summit 2025.
Welcome to QA Summit 2025.Welcome to QA Summit 2025.
Welcome to QA Summit 2025.
QA Summit
 
Best HR and Payroll Software in Bangladesh - accordHRM
Best HR and Payroll Software in Bangladesh - accordHRMBest HR and Payroll Software in Bangladesh - accordHRM
Best HR and Payroll Software in Bangladesh - accordHRM
accordHRM
 
Exchange Migration Tool- Shoviv Software
Exchange Migration Tool- Shoviv SoftwareExchange Migration Tool- Shoviv Software
Exchange Migration Tool- Shoviv Software
Shoviv Software
 
Do not let staffing shortages and limited fiscal view hamper your cause
Do not let staffing shortages and limited fiscal view hamper your causeDo not let staffing shortages and limited fiscal view hamper your cause
Do not let staffing shortages and limited fiscal view hamper your cause
Fexle Services Pvt. Ltd.
 
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
Ranking Google
 
How I solved production issues with OpenTelemetry
How I solved production issues with OpenTelemetryHow I solved production issues with OpenTelemetry
How I solved production issues with OpenTelemetry
Cees Bos
 
Time Estimation: Expert Tips & Proven Project Techniques
Time Estimation: Expert Tips & Proven Project TechniquesTime Estimation: Expert Tips & Proven Project Techniques
Time Estimation: Expert Tips & Proven Project Techniques
Livetecs LLC
 
Autodesk Inventor Crack (2025) Latest
Autodesk Inventor    Crack (2025) LatestAutodesk Inventor    Crack (2025) Latest
Autodesk Inventor Crack (2025) Latest
Google
 
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World ExamplesMastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
jamescantor38
 
GC Tuning: A Masterpiece in Performance Engineering
GC Tuning: A Masterpiece in Performance EngineeringGC Tuning: A Masterpiece in Performance Engineering
GC Tuning: A Masterpiece in Performance Engineering
Tier1 app
 
Comprehensive Incident Management System for Enhanced Safety Reporting
Comprehensive Incident Management System for Enhanced Safety ReportingComprehensive Incident Management System for Enhanced Safety Reporting
Comprehensive Incident Management System for Enhanced Safety Reporting
EHA Soft Solutions
 
Programs as Values - Write code and don't get lost
Programs as Values - Write code and don't get lostPrograms as Values - Write code and don't get lost
Programs as Values - Write code and don't get lost
Pierangelo Cecchetto
 
Digital Twins Software Service in Belfast
Digital Twins Software Service in BelfastDigital Twins Software Service in Belfast
Digital Twins Software Service in Belfast
julia smits
 
Download 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-ActivatedDownload 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-Activated
Web Designer
 
AEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural MeetingAEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural Meeting
jennaf3
 
Mobile Application Developer Dubai | Custom App Solutions by Ajath
Mobile Application Developer Dubai | Custom App Solutions by AjathMobile Application Developer Dubai | Custom App Solutions by Ajath
Mobile Application Developer Dubai | Custom App Solutions by Ajath
Ajath Infotech Technologies LLC
 
Robotic Process Automation (RPA) Software Development Services.pptx
Robotic Process Automation (RPA) Software Development Services.pptxRobotic Process Automation (RPA) Software Development Services.pptx
Robotic Process Automation (RPA) Software Development Services.pptx
julia smits
 
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studiesTroubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Tier1 app
 
Buy vs. Build: Unlocking the right path for your training tech
Buy vs. Build: Unlocking the right path for your training techBuy vs. Build: Unlocking the right path for your training tech
Buy vs. Build: Unlocking the right path for your training tech
Rustici Software
 
Memory Management and Leaks in Postgres from pgext.day 2025
Memory Management and Leaks in Postgres from pgext.day 2025Memory Management and Leaks in Postgres from pgext.day 2025
Memory Management and Leaks in Postgres from pgext.day 2025
Phil Eaton
 
Welcome to QA Summit 2025.
Welcome to QA Summit 2025.Welcome to QA Summit 2025.
Welcome to QA Summit 2025.
QA Summit
 
Best HR and Payroll Software in Bangladesh - accordHRM
Best HR and Payroll Software in Bangladesh - accordHRMBest HR and Payroll Software in Bangladesh - accordHRM
Best HR and Payroll Software in Bangladesh - accordHRM
accordHRM
 
Exchange Migration Tool- Shoviv Software
Exchange Migration Tool- Shoviv SoftwareExchange Migration Tool- Shoviv Software
Exchange Migration Tool- Shoviv Software
Shoviv Software
 
Do not let staffing shortages and limited fiscal view hamper your cause
Do not let staffing shortages and limited fiscal view hamper your causeDo not let staffing shortages and limited fiscal view hamper your cause
Do not let staffing shortages and limited fiscal view hamper your cause
Fexle Services Pvt. Ltd.
 
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
Ranking Google
 
How I solved production issues with OpenTelemetry
How I solved production issues with OpenTelemetryHow I solved production issues with OpenTelemetry
How I solved production issues with OpenTelemetry
Cees Bos
 
Time Estimation: Expert Tips & Proven Project Techniques
Time Estimation: Expert Tips & Proven Project TechniquesTime Estimation: Expert Tips & Proven Project Techniques
Time Estimation: Expert Tips & Proven Project Techniques
Livetecs LLC
 
Autodesk Inventor Crack (2025) Latest
Autodesk Inventor    Crack (2025) LatestAutodesk Inventor    Crack (2025) Latest
Autodesk Inventor Crack (2025) Latest
Google
 
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World ExamplesMastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
jamescantor38
 
GC Tuning: A Masterpiece in Performance Engineering
GC Tuning: A Masterpiece in Performance EngineeringGC Tuning: A Masterpiece in Performance Engineering
GC Tuning: A Masterpiece in Performance Engineering
Tier1 app
 
Comprehensive Incident Management System for Enhanced Safety Reporting
Comprehensive Incident Management System for Enhanced Safety ReportingComprehensive Incident Management System for Enhanced Safety Reporting
Comprehensive Incident Management System for Enhanced Safety Reporting
EHA Soft Solutions
 

Implementation of c string functions

  • 1. Prepared by Mohammed Sikander Technical Lead Cranes Software International Limited
  • 2.  size_t strlen(const char *str); mohammed.sikander@cranessoftware.com 2 size_t mystrlen(const char *str) { const char *end = str; while( *end != ‘0’) end++; return end – str; }
  • 3. char * strcpy(char *dest, const char *src); mohammed.sikander@cranessoftware.com 3 void mystrcpy(char *dest, const char *src) { while(1) { *dest = *src; if(*dest == ‘0’) return; src++; dest++; } }
  • 4. char * strcpy(char *dest, const char *src); mohammed.sikander@cranessoftware.com 4 void mystrcpy(char *dest, const char *src) { while((*dest++ = *src++)) { } }
  • 5. mohammed.sikander@cranessoftware.com 5 void mystrncpy(char *dest, const char *src, size_t n) { for(int i = 0 ; i < n ; i++) { *dest = *src; if(*dest == ‘0’) return; src++; dest++; } } int main( ) { char str[20] = “KARNATAKA”; char s1[20] = “ABCDEFGHIJKLMN”; char s2[20] = “ABCDEFGHIJKLMN”; mystrncpy(s1 , str ,5); mystrncpy(s2 , str , 12); printf(“s1 = %s n” , s1); printf(“s2 = %s n” , s2); }
  • 6. int strcmp(const char *str1 , const char *str2); mohammed.sikander@cranessoftware.com 6 int mystrcmp(const char *str1 , const char *str2) { while(1) { if(*str1 != *str2) return *str1 - *str2; if(*str1 == ‘0’) return 0; str1++; str2++; } } while(*str1 == *str2 && *str1 != ‘0’) { str1++; str2++; } return *str1 - *str2;
  • 7. int strncmp(const char *str1 , const char *str2,size_t n); mohammed.sikander@cranessoftware.com 7 int mystrcmp(const char *str1 , const char *str2,size_t n) { for(int I = 0 ; i < n ; i++) { if(*str1 != *str2) return *str1 - *str2; if(*str1 == ‘0’) return 0; str1++; str2++; } return 0; } int main( ) { char str1[ ] = “ BANGALORE”; char str2[ ] = “BANGKOK”; int res; res = mystrncmp(str1 , str2 , 3) ; printf(“res = %d “ , res); res = mystrncmp(str1 , str2 , 5) ; printf(“res = %d “ , res); }
  • 8. int strcmpi(const char *str1 , const char *str2); mohammed.sikander@cranessoftware.com 8 int mystrcmpi(const char *str1 , const char *str2) { while(1) { char x = toupper(*str1); char y = toupper(*str2); if(x != y) return x - y; if(*str1 == ‘0’) return 0; str1++; str2++; } } int main( ) { char str1 [ ] = “ BANGALORE “; char str2 [ ] = “bangalore”; int res; res = mystrcmpi( str1 , str2); printf(“res = %d “ , res); }
  • 9. void mystrrev(char *startptr) { int len = strlen(startptr); char *endptr = startptr + len - 1; while(startptr < endptr) { myswap(startptr , endptr); startptr++; endptr--; } } mohammed.sikander@cranessoftware.com 9 void myswap(char *a,char *b) { char temp = *a; *a = *b; *b = temp; } int main( ) { char str[ ] = “ SIKANDER”; printf(“str = %s” , str); mystrrev(str); printf(“n After Reverse n”); printf(“str = %s” , str); }
  • 10. char *strchr(const char *str, char key); char *mystrchr(const char *str , char key) { while(*str != ‘0’) { if(*str == key) return str; str++; } return NULL; } mohammed.sikander@cranessoftware.com 10 int main( ) { char str[ ] = “BANGALORE”; char *ptr; ptr = mystrchr(str , ‘A’); if(ptr == NULL) printf(“Key Not found”); else printf(“Found at index “ , ptr – str); ptr = mystrchr(str , ‘C’); if(ptr == NULL) printf(“Key Not found”); else printf(“Found at index “ , ptr – str); }
  • 11. char *strrchr(const char *str, char key); char *mystrrchr(const char *start , char key) { int len = strlen(str); char *end = start + len – 1; while(end > start) { if(*end == key) return end; end--; } return NULL; } mohammed.sikander@cranessoftware.com 11 int main( ) { char str[ ] = “BANGALORE”; char *ptr; ptr = mystrrchr(str , ‘A’); if(ptr == NULL) printf(“Key Not found”); else printf(“Found at index “ , ptr – str); ptr = mystrrchr(str , ‘C’); if(ptr == NULL) printf(“Key Not found”); else printf(“Found at index “ , ptr – str); }
  • 12. char * mystrcat(char *dest , const char *src) { int len = strlen(dest); mystrcpy(dest + len , src); return dest; } mohammed.sikander@cranessoftware.com 12 char *mystrncat(char *dest , const char *src,size_t n) { int len = strlen(dest); mystrncpy(dest + len , src , n ); }
  • 13. char * mystrstr(char *str , char *key) { int len = strlen(key); char *ptr; while(1) { ptr = strchr(str , *key); if(ptr == NULL) return NULL; int res = strncmp(ptr , key , len); if(res != 0) return ptr; str = ptr + 1; } } mohammed.sikander@cranessoftware.com 13 Main String : BANGALORE Sub String to Search : GAL GALA LOT
  翻译: