Recursion can be used to do both tasks in one line. Below are one line implementations for stracat() and strcmp().
The function my_strcmp() is simple compared to my_strcmp().
The above functions do very basic string concatenation and string comparison. These functions do not provide same functionality as standard library functions.
Please write comments if you find the above code incorrect, or find better ways to solve the same problem.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Write a one line C function to round floating point numbers
- strcat() vs strncat() in C++
- strcmp() in C/C++
- Difference between strncmp() and strcmp in C/C++
- C program to print odd line contents of a File followed by even line content
- When should we write our own assignment operator in C++?
- Write your own memcpy() and memmove()
- When should we write our own copy constructor?
- Write a C program that won't compile in C++
- How to write your own header file in C?
- Read/Write structure to a file in C
- Write a C macro PRINT(x) which prints x
- C program to write an image in PGM format
- Write a program that produces different results in C and C++
- How to write a running C code without main()?
- Does C++ compiler create default constructor when we write our own?
- Write a C program that does not terminate when Ctrl+C is pressed
- fopen() for an existing file in write mode
- Write your own strlen() for a long string padded with '\0's
- How to write long strings in Multi-lines C/C++?