题目描述
Please create a function to extract the filename extension from the given path,return the extracted filename extension or null if none.
输入描述:
输入数据为一个文件路径
输出描述:
对于每个测试实例,要求输出对应的filename extension
示例1
输入
Abc/file.txt
输出
txt
#include <bits/stdc++.h>
using namespace std;
int main()
{
char ch[100];
char ex[100];
gets(ch);
int len = strlen(ch);
int cnt = 0;
int flag = 0;
for(int i=len-1; i>=0; i--)
{
if(ch[i]=='.')
{
flag=1;
break;
}
ex[cnt++]=ch[i];
}
if(flag == 0)
printf("null\n");
else
{
for(int i=cnt-1; i>=0; i--)
printf("%c",ex[i]);
printf("\n");
}
return 0;
}