#include <stdio.h>
#include <string.h>
#include <conio.h>
int checkunderscore(char); //function declaration
int main()
{
char input[50], output[50];
int i, j = 0;
printf("Enter a string\n");
gets(input);
for(i = 0; input[i] != '\0'; i++) //for whole of the input string
{
if(checkunderscore(input[i]) == 0) //check whether function returns 0
{
output[j] = input[i];
j++; //increment output index
}
}
output[j] = '\0';
printf("\n String after removing underscores: %s\n", output);
getch();
return 0;
}
int checkunderscore(char c)
{
if(c=='_')
return 1; // returns true
else
return 0; //returns false
}
Output :
C program to remove underscore from a string
#include <string.h>
#include <conio.h>
int checkunderscore(char); //function declaration
int main()
{
char input[50], output[50];
int i, j = 0;
printf("Enter a string\n");
gets(input);
for(i = 0; input[i] != '\0'; i++) //for whole of the input string
{
if(checkunderscore(input[i]) == 0) //check whether function returns 0
{
output[j] = input[i];
j++; //increment output index
}
}
output[j] = '\0';
printf("\n String after removing underscores: %s\n", output);
getch();
return 0;
}
int checkunderscore(char c)
{
if(c=='_')
return 1; // returns true
else
return 0; //returns false
}
Output :