Removing first and last character of a string in C
In this post we will give you information about Removing first and last character of a string in C. Hear we will give you detail about Removing first and last character of a string in CAnd how to use it also give you demo for it if it is necessary.
we are going to learn about how to remove the first and last character of a string in C.
Consider, we have the following string.
char color[5] = "green";
Now, we want to remove the first character g and the last character n from the above string.
Removing the first and last character
To remove the first and last character of a string, we can use the following syntax in C.
Here is an example:
#include <stdio.h>#include <string.h>int main() { char color[5] = "green"; char *result = color+1; // removes first character result[strlen(result)-1] = ' '; // removes last character printf("%sn",result);}
Output:
"ree"
In the example above, we removed the first character of a string by changing the starting point of a string to index position 1, then we removed the last character by setting its value to .
In C means the ending of a string.
Hope this code and post will helped you for implement Removing first and last character of a string in C. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs