Reverse String Till Underscore
C CODE:
#include<stdio.h>
#include <stdlib.h>
int main()
{
char a[100];
fgets(a,100,stdin);
int i,j,k=0,l,g=0;
l=strlen(a);
for(i=0;i<l;i++)
{
if(a[i]=='_')
{
k=i;
g=1;
}
}
if(g==1)
{
for(i=k-1;i>=0;i--)
{
printf("%c",a[i]);
}for(i=k;i<l;i++)
{
printf("%c",a[i]);
}
}else
{
for(i=l-1;i>=0;i--)
{
printf("%c",a[i]);
}
}
}
empty line is printing on first
ReplyDeleteGet the input as scanf("%[^\n]%*c",a);
ReplyDeletesuper
Deletecan i get python code for same ques?
ReplyDelete