Header Ads Widget

Harry's FIle

Problem:-

Harry Potter got a challenge to unlock the path and tell its filename and extension.
He uses "Alohomora"  to unlock the file path and break the code just like Hermione used to unlock the door.
Help him to unlock the path and extract the file path, file name and its extension as shown below:
Input:
First line of input contains path of string type.
Output:
First line displays path ,second line displays file name,Third line displays extension
SAMPLE INPUT
 
C:\Users\admin\Pictures\flower.jpg
SAMPLE OUTPUT
 
Path: C:\Users\admin\Pictures\
File name: flower
Extension: jpg
Explanation
The input String can be divided into three parts, the path, file name and extension. These three parts are separated by a backslash character and a dot as shown in the figure below.
Time Limit:5.0 sec(s) for each input file.
Memory Limit:256 MB
Source Limit:1024 KB

solution:-

#include<string.h>
#include<stdio.h>
main()
{
char s[100],n[8],e[3];
int l,l1,i,j=0,x,k;
scanf("%s",s);
l=strlen(s);
for(i=l-1;i>=0;i--)
{
x=s[i];
while(s[i]!='.')
{
e[j]=s[i];
i--;
j++;
}
i--;
j=0;
x=s[i];
while(1)
{
n[j]=s[i];
i--;
j++;
x=s[i];
if(x==92)
break;
}
break;
}
printf("Path: ");
for(k=0;k<=i;k++)
printf("%c",s[k]);
printf("\n");
printf("File name: ");
for(k=j-1;k>=0;k--)
printf("%c",n[k]);
printf("\nExtension: ");
for(k=2;k>=0;k--)
printf("%c",e[k]);
}

Post a Comment

0 Comments