We, the C programmers, sometimes face a problem that we are to reverse a number or a string. On many online judges there are some problems like number reversion. On these cases, what will we do? We may consider the following code to reverse a number: #include <stdio.h> int main() { int i, x = 12345, rev[5]; for(i = 0; i < 5; i++){ rev[i] = x % 10; x = x/10; printf("%d", rev[i]); } return 0; } Output:

Continue reading

strrev function is defined in string.h header file. It reverses a given string. Its basic form is given below: **strrev(str);** Here str, a string, is a parameter of strrev() function. This function reverses this string. Please consider the following program: #include <stdio.h> #include <string.h> int main() { char str[100]; gets(str); puts(strrev(str)); return 0; } Input: coder Output: redoc By using this program I mean strrev function, you can reverse any number or string.

Continue reading

Today we will talk about a string assignment operator. But before that, we will solve a problem. The problem is very easy. We have to copy/assign one string to another.

Suppose str1 & str2 are two strings. We have to copy/assign str2 to str1. We may try this as follows:

Continue reading

**strlen function **is a very simple string library function defined in string.h header file. It returns the length of a given byte string. Here length means how many characters are containing in that string. But it’s noted that the null character will always be excluded from the length. Its basic form is given below: **strlen(string);** Here ‘string’ is the parameter of this function. This function returns an integer which indicates the length of string.

Continue reading

To understand this topic clearly, you should understand the strcmp function in C programming firstly. If you have understood already, then go ahead. strncmp function is a variation of strcmp function. It compares a certain amount of characters of two null-terminated byte strings. The basic form is given below: **strncmp(str1, str2, n);** Here str1, str2 & n are the three parameters of this function. str1 & str2 are two null-terminated byte strings and n is an integer.

Continue reading

If you understand the strcat function in C programming, then a question may appear in your subconscious (not sure) mind. That is about the concatenation of certain amount of two strings. For such kind of concatenation we can use another function defined in string.h header file. That is strncat function. Its basic form is given below: **strncat(str1, str2, n);** This function contains three parameters – str1 & str2 are two strings and n indicates an integer.

Continue reading

Author's picture

Maksudur Rahman Maateen

DevOps Engineer | Site Reliability Engineer

Grameen Telecom Trust

Bangladesh