I am trying to write a function that reverses a given string but it gives me "stack smashing detected".
Here is my code:
void reverse(char *str2) {
int i, j;
char temp;
for (i = 0, j = str2[strlen(str2) - 1]; i < j; i++, j--) {
temp = str2[i];
str2[i] = str2[j];
str2[j] = temp;
}
str2[strlen(str2)] = '\0';
printf("%s", str2);
}
There are multiple problems in your code:
j should be initialized as j = strlen(str2) - 1, not j = str2[strlen(str2) - 1] which is the value of the last character in the string (if any).
str2[strlen(str2)] = '\0'; is absolutely useless and redundant.
Here is a modified version:
#include <stdio.h>
#include <string.h>
void reverse(char *str) {
for (size_t i = 0, j = strlen(str); i < j--; i++) {
char temp = str[i];
str[i] = str[j];
str[j] = temp;
}
printf("%s\n", str);
}
Such a function should return a pointer to the reversed string. That is it is better to declare the function like
char * reverse( char *str2 );
Also the name of the parameter looks strange. So declare the function like
char * reverse( char *s );
There is a typo in the function. The variable j must be initialized like
j = strlen( str2 ) - 1;
instead of
j = str2[strlen(str2) - 1];
This statement
str2[strlen(str2)] = '\0';
is redundant and should be removed.
The function should not output the reversed string. It is the caller of the function that will decide whether to output the reversed string.
Also instead of the type int for indices you should use the type size_t - the return type of the function strlen.
Using your approach the function should look the following way
char * reverse( char *s )
{
if ( *s )
{
for ( size_t i = 0, j = strlen( s ) - 1; i < j; i++, j-- )
{
char temp = s[i];
s[i] = s[j];
s[j] = temp;
}
}
return s;
}
Here is a demonstration program.
#include <stdio.h>
#include <string.h>
char * reverse( char *s )
{
if ( *s )
{
for ( size_t i = 0, j = strlen( s ) - 1; i < j; i++, j-- )
{
char temp = s[i];
s[i] = s[j];
s[j] = temp;
}
}
return s;
}
int main(void)
{
char s[] = "Hello World!";
puts( s );
puts( reverse( s ) );
}
Its output is
Hello World!
!dlroW olleH
Related
I am trying to reverse this C-string and I thought I did it correct but the string remains the same when it passes through the function.
#include <stdio.h>
char* reverse(char* string);
int main(int arc, char* argv[]) {
char word[] = "Hello World!";
printf("%s\n", word);
printf("%s\n", reverse(word));
return 0;
}
char* reverse(char* string) {
int i, j, n = 0;int len = 0;char temp;
//Gets string length
for (i = 0; *(string + i) != '0'; i++) {
len++;
}
//Reverses string
for (j = len - 1; j >= 0; j--) {
temp = string[n];
string[n] = string[j];
string[j] = temp;
n++;
}
return &string[0];
}
Expected output:
Hello World!
!dlroW olleH
For starters there is a typo
for (i = 0; *(string + i) != '0'; i++) {
You have to write
for (i = 0; *(string + i) != '\0'; i++) {
That is instead of the character '0' you have to use '\0' or 0.
In this for loop
for (j = len - 1; j >= 0; j--) {
temp = string[n];
string[n] = string[j];
string[j] = temp;
n++;
}
the string is reversed twice.:) As a result you get the same string.
The function can look for example the following way
char * reverse(char *string)
{
//Gets string length
size_t n = 0;
while ( string[n] != '\0' ) ++n;
//Reverses string
for ( size_t i = 0, m = n / 2; i < m; i++ )
{
char temp = string[i];
string[i] = string[n - i - 1];
string[n - i - 1] = temp;
}
return string;
}
Or the function can be defined the following way using pointers
char * reverse(char *string)
{
//Gets string length
char *right = string;
while ( *right ) ++right;
//Reverses string
if ( right != string )
{
for ( char *left = string; left < --right; ++left )
{
char temp = *left;
*left = *right;
*right = temp;
}
}
return string;
}
The same approach of the function implementation without using pointers can look the following way
char * reverse(char *string)
{
//Gets string length
size_t n = 0;
while ( string[n] != '\0' ) ++n;
//Reverses string
if ( n != 0 )
{
for ( size_t i = 0; i < --n; ++i )
{
char temp = string[i];
string[i] = string[n];
string[n] = temp;
}
}
return string;
}
Here is one more solution. I like it most of all. Tough it is inefficient but it is not trivial as the early presented solutions. It is based on an attempt of one beginner to write a function that reverses a string.:)
#include <stdio.h>
#include <string.h>
char *reverse( char *string )
{
size_t n = 0;
while (string[n]) ++n;
while (!( n < 2 ))
{
char c = string[0];
memmove( string, string + 1, --n );
string[n] = c;
}
return string;
}
int main( void )
{
char string[] = "Hello World!";
puts( string );
puts( reverse( string ) );
}
The program output is
Hello World!
!dlroW olleH
Of course instead of manually calculating the length of a string in all the presented solutions there could be used standard string function strlen declared in the header <string.h>.
The problem is that the input word[] is an array, which decays to a pointer when passed to the reverse function.
In the for loop, instead of using n to keep track of the position, I suggest you to use i and j to keep track of the start and end of the string, and increment and decrement them respectively and use strlen to get the length of string.
Also, as it is mentionned above by #Vlad from Moscow, in your for loop you are checking for 0 but it should be \0 which is the null character.
Please find down below an update of your posted code that is generating the expected result :
#include <stdio.h>
char* reverse(char* string);
int main(int arc, char* argv[]) {
char word[] = "Hello World!";
printf("%s ", word);
printf("%s\n", reverse(word));
return 0;
}
char* reverse(char* string) {
int i, j;
char temp;
int len = strlen(string);
//Reverses string
for (i = 0, j = len - 1; i < j; i++, j--) {
temp = string[i];
string[i] = string[j];
string[j] = temp;
}
return &string[0];
}
The output is as expected: Hello World! !dlroW olleH
Aditionnally, you can include the header <string.h> or explicitly
provide a declaration for 'strlen' to avoid the warning that indicate to implicitly declaring library function 'strlen' with type 'unsigned long (const char *)' [-Wimplicit-function-declaration]
zfill algorithm is supposed to work as follows:
zfill function accepts two parameters, a string and a number,
if string length is >= the number, then it doesn't have to add anything, and it returns a copy to the string,
else, malloc enough space and add zeros before the string.
I'm trying to understand why is this solution not correct, it has two warnings:
1st warning:
for (i; i < zeros; i++) {
s[i] = "0";
}
"=": char differs in level of indirection from char[2]
2nd warning:
for (i; i < n; i++) {
s[i] = str[i];
}
buffer overrun while writing to s
char* zfill(const char* str, size_t n) {
if (str == NULL) {
return NULL;
}
char* s;
size_t length = strlen(str);
if (length >= n) {
//it doesn't have to add anything, just malloc and copy the string
size_t sum = length + 1u;
s = malloc(sum);
if (s == NULL) {
return NULL;
}
for (size_t i = 0; i < length; i++) {
s[i] = str[i];
}
s[sum] = 0;
}
else {
// add zeros before strings
size_t zeros = n - length;
size_t sum = n + 1u;
s = malloc(sum);
if (s == NULL) {
return NULL;
}
size_t i = 0;
for (i; i < zeros; i++) {
s[i] = "0";
}
for (i; i < n; i++) {
s[i] = str[i];
}
s[sum] = 0;
}
return s;
}
int main(void) {
char str[] = "hello, world!";
size_t n = 40;
char* s = zfill(str, n);
free(s);
return 0;
}
EDIT: I've solved the problem this way:
char* zfill(const char* str, size_t n) {
if (str == NULL) {
return NULL;
}
char* s;
size_t length = strlen(str);
if (length >= n) {
//it doesn't have to add anything, just malloc and copy the string
size_t sum = length + 1u;
s = malloc(sum);
if (s == NULL) {
return NULL;
}
for (size_t i = 0; i < length; i++) {
s[i] = str[i];
}
s[sum-1] = 0;
}
else {
// add zeros before strings
size_t zeros = n - length;
size_t sum = n + 1u;
s = malloc(sum);
if (s == NULL) {
return NULL;
}
size_t i = 0;
for (i; i < zeros; i++) {
s[i] = '0';
}
for (size_t j = 0; i < n; j++) {
s[i++] = str[j];
}
s[sum-1] = 0;
}
return s;
}
and it works, but I don't know why I have this warning:
for (i; i < zeros; i++) {}
statement with no effect
but when I've debugged I've noticed that this statement has an effect, because it correctly copies the correct number of zeros. I don't know why I have this warning
SO is a place of learning.
When first dealing with a coding challenge, it's best to take time to work out what's needed before starting to write code.
Below is a working version of zfill() (along with a main() that tests it.)
Read through the comments. The only thing new here is memset().
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// A trivial "helper function" determines the max of two values
int max( int a, int b ) { return a > b ? a : b; }
char *zfill( char *str, int minLen ) {
// Determine length of arbitrary string
int len = strlen( str );
// Determine max of length v. minimum desired
int allocSize = max( minLen, len );
// allocate buffer to store resulting string (with '\0')
char *obuf = (char*)malloc( allocSize + 1 );
/* omitting test for failure */
// determine start location at which to copy str
int loc = len <= minLen ? minLen - len : 0;
if( loc > 0 )
// fill buffer with enough 'zeros'
memset( obuf, '0', allocSize ); // ASCII zero!
// copy str to that location in buffer
strcpy( obuf + loc, str );
// return buffer to calling function
return obuf;
}
int main() {
// collection of strings of arbitrary length
char *strs[] = { "abc", "abcdefghijkl", "abcde", "a", "" };
// pass each one to zfill, print, then free the alloc'd buffer.
for( int i = 0; i < sizeof strs/sizeof strs[0]; i++ ) {
char *cp = zfill( strs[i], 10 );
puts( cp );
free( cp );
}
return 0;
}
Output:
0000000abc
abcdefghijkl
00000abcde
000000000a
0000000000
Here's zfill() without the comments:
char *zfill( char *str, int minLen ) {
int len = strlen( str );
int allocSize = max( minLen, len );
char *obuf = (char*)malloc( allocSize + 1 );
/* omitting test for failure */
int loc = len <= minLen ? minLen - len : 0;
if( loc > 0 )
memset( obuf, '0', loc ); // ASCII zero!
strcpy( obuf + loc, str );
return obuf;
}
You don't want to spend your time staring at lines and lines of code.
Fill your quiver with arrows that are (proven!) standard library functions and use them.
I've omitted, too, the test for zfill being passed a NULL pointer.
This code snippet
size_t sum = length + 1u;
s = malloc(sum);
//...
s[sum] = 0;
accesses memory outside the allocated character array because the valid range of indices is [0, sum). You need to write at least like
s[length] = 0;
In this code snippet
for (i; i < zeros; ++) {
s[i] = "0";
}
the expression s[i] represents a single object of the type char while on the right-hand side there is a string literal that as an expression has the type char *. You need to write at least
s[i] = '0';
using the integer character constant instead of the string literal.
In this code snippet
size_t i = 0;
for (i; i < zeros; i++) {
s[i] = "0";
}
for (i; i < n; i++) {
s[i] = str[i];
}
as the length of the string str can be less than n then this for loop
for (i; i < n; i++) {
s[i] = str[i];
}
accesses memory outside the string str.
Pay attention to that your function has redundant code. It can be written simpler.
The function can look for example the following way as shown in the demonstration program below.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char * zfill( const char *s, size_t n )
{
char *result = NULL;
if ( s != NULL )
{
size_t len = strlen( s );
n = len < n ? n : len;
result = malloc( n + 1 );
if ( result )
{
size_t i = 0;
size_t m = len < n ? n - len : 0;
for ( ; i < m; i++ )
{
result[i] = '0';
}
for ( ; i < n; i++ )
{
result[i] = s[i - m];
}
result[i] = '\0';
}
}
return result;
}
int main( void )
{
const char *s = "Hello";
size_t n = 10;
char *result = zfill( s, n );
if ( result ) puts( result );
free( result );
}
The program output is
00000Hello
Or as #Some programmer dude pointed to in his comment you can use the standard C function snprintf that alone performs the task. For example
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char * zfill( const char *s, size_t n )
{
char *result = NULL;
if ( s != NULL )
{
size_t len = strlen( s );
n = len < n ? n : len;
result = malloc( n + 1 );
if ( result )
{
int m = len < n ? n - len : 0;
snprintf( result, n + 1, "%.*d%s", m, 0, s );
}
}
return result;
}
int main( void )
{
char *p = zfill( "Hello", 5 );
if ( p ) puts( p );
free( p );
p = zfill( "Hello", 10 );
if ( p ) puts( p );
free( p );
}
The program output is
Hello
00000Hello
so you have 3 major problems in your code :
it's s[i] = '0'; not s[i] = "0";
it's s[i] = str[i - zeros]; not s[i] = str[i]; as the value of the i will be 27 in your test case : so it make sense to say s[27] because its size is about 41 but it doesn't make sense to say str[27] as its size is only about 13 in your test case , so you had to map the value 27 of i to the value 0 to be convenient to use with str
i is deprecated in first part here for (i; i < zeros; i++) , so use for (; i < zeros; i++)instead of for (i; i < zeros; i++) , but it will not cause any problem if you keep it.
and here is the full edited code :
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
char* zfill(const char* str, size_t n) {
if (str == NULL) {
return NULL;
}
char* s;
size_t length = strlen(str);
if (length >= n) {
//it doesn't have to add anything, just malloc and copy the string
size_t sum = length + 1u;
s = malloc(sum);
if (s == NULL) {
return NULL;
}
for (size_t i = 0; i < length; i++) {
s[i] = str[i];
}
s[sum] = 0;
}
else {
// add zeros before strings
size_t zeros = n - length;
size_t sum = n + 1u;
s = malloc(sum);
if (s == NULL) {
return NULL;
}
size_t i = 0;
for (; i < zeros; i++) {
s[i] = '0';
}
for (; i < n; i++) {
s[i] = str[i - zeros];
}
s[sum] = 0;
}
return s;
}
int main(void) {
char str[] = "hello, world!";
size_t n = 40;
char* s = zfill(str, n);
printf("%s\n", s);
free(s);
return 0;
}
I have written this exercise which should remove any chars in the first argument string which appear in the second string. But the result is a segmentation fault for the arguments below. Can any one explain to me what am I missing?
#include <stdio.h>
void squeez(char s1[], char s2[])
{
int i, j, k, match;
while (s1[i] != '\0') {
match = 0;
for (k = 0; s2[k] != '\0'; ++k) {
if (s1[i] == s2[k]) {
match = 1;
break;
}
}
if (match) {
i++;
} else {
s1[j++] = s1[i++];
}
}
s1[j] = '\0';
}
int main()
{
char s[] = "asdsffffsffsk";
char x[] = "sf";
squeez(s, x);
printf("%s %s", s, x);
return 0;
}
For starters the function should be declared the following way
char * squeez( char s1[], const char s2[] );
That is the second parameter should have the qualifier const because the string specified by this parameter is not changed in the function.
The function should follow the general convention of C standard string functions and return pointer to the result string.
Within the function variables i and j are not initialized and have indeterminate values. So even the first while loop
int i, j, k, match;
while (s1[i] != '\0') {
// ...
invokes undefined behavior.
Instead of the type int of these variables you should use the type size_t because the type int can be not large enough to store lengths of strings.
You should declare variables in minimum scopes where they are used.
Keeping your approach to the function definition it can look the following way as it is shown in the demonstrative program below.
#include <stdio.h>
char * squeez( char s1[], const char s2[] )
{
size_t i = 0, j = 0;
while ( s1[i] != '\0' )
{
int match = 0;
for ( size_t k = 0; !match && s2[k] != '\0'; ++k )
{
if ( s1[i] == s2[k] ) match = 1;
}
if ( !match ) s1[j++] = s1[i];
i++;
}
s1[j] = '\0';
return s1;
}
int main(void)
{
char s[] = "asdsffffsffsk";
char x[] = "sf";
puts( squeez( s, x ) );
return 0;
}
The program output is
adk
Also as the variable i is not used outside the while loop then the while loop could be substituted for a for loop where the variable i will be declared. For example
char * squeez( char s1[], const char s2[] )
{
size_t j = 0;
for ( size_t i = 0; s1[i] != '\0'; i++ )
{
int match = 0;
for ( size_t k = 0; !match && s2[k] != '\0'; ++k )
{
if ( s1[i] == s2[k] ) match = 1;
}
if ( !match ) s1[j++] = s1[i];
}
s1[j] = '\0';
return s1;
}
I noticed that the i and j are not initialized. In fact, your code is workable without the problem that I put forward. This is the code I tried.
#include <stdio.h>
void squeez(char s1[], char s2[])
{
int index1 = 0, position = index1, index2 = 0;
int match = 0;
while (s1[index1] != '\0')
{
match = 0;
for (index2 = 0; s2[index2] != '\0'; index2++)
{
if (s1[index1] == s2[index2])
{
match = 1;
break;
}
}
if (match)
index1++;
else
s1[position++] = s1[index1++];
}
s1[position] = '\0';
}
int main()
{
char s[] = "asdsffffsffsk";
char x[] = "sf";
squeez(s, x);
printf("%s %s", s, x);
return 0;
}
#include <stdio.h>
void revstr(char str[])
{
char temp;
int size = 0;
while(*str != '\0'){
size++;
str++;
}
for (int i = 0; i < size/2; i++)
{
temp = str[i];
str[i] = str[size-1-i];
str[size-1-i] = temp;
}
for(int i = 0; i < size; i++)
{
printf("%c\n", *(str+i));
}
}
int main()
{
char str[20];
printf("enter a string: \n");
scanf("%s", &str);
revstr(str);
return 0;
}
why is my rev string not printing the reverse of the string it is printing out some garbage value.
can you point out why?
After this while loop
while(*str != '\0'){
size++;
str++;
}
the pointer str does not point to the beginning of the string.
Instead you could write for example
while( str[size] != '\0'){
size++;
}
Nevertheless such a function should do only one thing: to reverse a string. It is the caller of the function that decides whether to output the reversed string.
So the function can look like
char * revstr( char s[] )
{
size_t n = 0;
while ( s[n] ) ++n;
for ( size_t i = 0; i < n / 2; i++ )
{
char c = s[i];
s[i] = s[n - i - 1];
s[n - i - 1] = c;
}
return s;
}
and in main you could write
puts( revstr( str ) );
Here is a demonstrative program.
#include <stdio.h>
char * revstr( char s[] )
{
size_t n = 0;
while ( s[n] ) ++n;
for ( size_t i = 0; i < n / 2; i++ )
{
char c = s[i];
s[i] = s[n - i - 1];
s[n - i - 1] = c;
}
return s;
}
int main(void)
{
char s[] = "Hello";
puts( s );
puts( revstr( s ) );
return 0;
}
The program output is
Hello
olleH
Of course instead of the while loop you could use the standard string function strlen.
size_t n = strlen( s );
Pay attention to that in the call of scanf
scanf("%s", &str);
the second argument shall be the expression str
scanf("%s", str);
I would implement it another way:
char *reverse(char *str)
{
char *wrk = str, *end = str;
if(str && *str)
{
while(*(end + 1)) end++;
while(end > wrk)
{
char tmp = *end;
*end-- = *wrk;
*wrk++ = tmp;
}
}
return str;
}
It is good to check if the parameter is correct.
I would return the value. It allows you to use the reversed string in expressions and as a function parameter. Example below:
int main(void)
{
char s[] = "Hello world";
printf("%s\n", reverse(s));
}
https://godbolt.org/z/fbo4nsn38
In your code you advance the pointer str to calculate its length but you forgot to reset it to the start after that. Also, your call to scanf should pass str, not its address. Moreover scanf will write beyond the end of str if the user enters a string longer than 19 characters. Try this instead:
#include <stdio.h>
#include <string.h>
void revstr(char str[])
{
char temp;
int size = strlen(str);
for (int i = 0; i < size / 2; i++) {
temp = str[i];
str[i] = str[size - 1 - i];
str[size - 1 - i] = temp;
}
}
int main()
{
char str[20];
printf("enter a string: \n");
fgets(str, sizeof(str), stdin);
str[strcspn(str, "\n")] = '\0';
revstr(str);
printf("%s\n", str);
return 0;
}
I need to delete all letters from s1 which are in s2.
I can't understand what is wrong with my code:
#include <stdio.h>
#include <stdlib.h>
void squeeze(char s1[], char s2[])
{
int i,j;
i=j=0;
for(i; s2[i]!='\0'; i++) {
for (j; s1[j] != '\0'; j++) {
if (s1[j] == s2[i]) {
s1[j] = s1[j + 1];
--j;
}
}
}
}
int main()
{
char w1[] = "abcde";
char w2[] = "fghaj";
squeeze(w1,w2);
puts(w1);
return 0;
}
but the output is:
abcde
What should I repair?
For starters the variable j is not reset to 0 in the inner loop for each iteration of the outer loop.
Secondly if a character has to be removed then all characters after it are not being moved to the left one position. You are simply replacing the removed character with the next character in the string.
The function can look the following way as it is shown in the demonstrative program below.
#include <stdio.h>
#include <string.h>
char * squeeze( char s1[], const char s2[] )
{
for ( char *p = s1, *q = s1; *q; ++p )
{
if ( !*p || !strchr( s2, *p ) )
{
if ( q != p )
{
*q = *p;
}
if ( *p ) ++q;
}
}
return s1;
}
int main( void )
{
char w1[] = "abcde";
char w2[] = "fghaj";
puts( squeeze( w1, w2 ) );
return 0;
}
The program output is
bcde
If you are not allowed to use standard string functions and pointers then the program can look the following way.
#include <stdio.h>
char * squeeze( char s1[], const char s2[] )
{
for ( size_t i = 0, j = 0; s1[j] != '\0'; ++i )
{
size_t k = 0;
while ( s2[k] != '\0' && s2[k] != s1[i] ) ++k;
if ( s2[k] == '\0' )
{
if ( j != i )
{
s1[j] = s1[i];
}
if ( s1[i] != '\0' ) ++j;
}
}
return s1;
}
int main( void )
{
char w1[] = "abcde";
char w2[] = "fghaj";
puts( squeeze( w1, w2 ) );
return 0;
}
The program output is the same as shown for the previous demonstrative program
bcde
Two problems in squeeze:
You need to reinitialize j to zero on every pass through the loop.
You need to copy the entire remained of the string one character to the left, not just the character following the one you want to remove.
I suggest you rewrite squeeze as:
void squeeze(char s1[], char s2[])
{
int i,j;
i=j=0;
for( ; s2[i]!='\0'; i++) {
for (j = 0; s1[j] != '\0'; j++) {
if (s1[j] == s2[i]) {
strcpy(s1+j, s1+j+1);
--j;
}
}
}
}
I see an issue here , your code is not entering this statement for some reason :
if (s1[j] == s2[i]) {
s1[j] = s1[j + 1];
--j;
}
your question might be why ? cause i and j are not set to 0 , try printing them and you will see that j will move to 4 but i is staying forever as 0
so as a start you can fix it by doing this
for(i=0; s2[i]!='\0'; i++) {
for (j=0; s1[j] != '\0'; j++) {
then you didn't copy the whole string and moved it back one step to rewrite over the found caracter , you only moved one caracter and left it blank
Exemple
input : abcde
output :b_cde
to fix this you have two methods :
use strcpy in order to move back one step the code
for(i=0; s2[i]!='\0'; i++) {
for (j=0; s1[j] != '\0'; j++) {
if (s1[j] == s2[i]){
strcpy(s1+j, s1+j+1);
--j;
}
}
or you can simply create the same function using a boucle for
for(i=0; s2[i]!='\0'; i++) {
for (j=0; s1[j] != '\0'; j++) {
if (s1[j] == s2[i]){
for (k=j;s1[k] != '\0';k++)
s1[k] = s1[k + 1];
--j;
}
}
#include <stdio.h>
#include <string.h>
int rem_str(char * porgstr, char * pdel) {
if (!porgstr || !pdel) {
return 0;
}
int i = 0;
int j = 0;
char tmp[256] = {0};
int len = strlen(pdel);
for (i = 0; i < len; i++) {
tmp[pdel[i]]++;
}
len = strlen(porgstr);
for (i = 0, j=0; i < len; i++) {
if(tmp[porgstr[i]] == 0) {
porgstr[j] = porgstr[i];
j++;
}
}
porgstr[j] = 0;
return 0;
}
int main () {
char * input1 = strdup("origional string passed to program");
char * input2 = strdup("sdel");
printf("Input before del : %s\n", input1);
rem_str(input1, input2);
printf("String after del : %s\n", input1);
return 0;
}
Output:
./a.out
Input before del : origional string passed to program
string after del : origiona tring pa to program