Showing posts with label Case conversion Hacker Earth Solution in C. Show all posts
Showing posts with label Case conversion Hacker Earth Solution in C. Show all posts

Monday, 31 August 2020

Case conversion Hacker Earth Solution in C

 https://www.hackerearth.com/practice/basic-programming/implementation/basics-of-implementation/practice-problems/algorithm/case-conversion-d19fbcfe/submissions/

#include<stdio.h>
#include<string.h>
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
char s[105],temp[200];
scanf(" %s", s);
strcpy(temp,s);
int i,j;
if(s[0] >= 'A' && s[0] <= 'Z')
temp[0]=s[0]+32;
for(i=1,j=1;s[i] != '\0';i++)
{
if(s[i] >= 'A' && s[i] <= 'Z')
{
temp[j++]='_';
temp[j++]=s[i]+32;
}
else
temp[j++]=s[i];
}
temp[j]='\0';
printf("%s\n", temp);
}
}