通过后缀名判断是C,C++,JAVA,还是其他语言

输入文件的后缀名,并判断是使用c,c++,java编写,还是其他编程语言编写
例如,输入b.c 输出c
输入a.cpp输出c++
输入c.java输出java

#include <stdio.h>
#include <string.h>
int main()
{
    int i,n,k,t=0,p=0,q=0;
    char str[20];
    gets(str);
    n=strlen(str);
    for(i=n-1;i>=0;i--)
    if(str[i-2]=='c'&&str[i-1]=='p'&&str[i]=='p')
        {printf("c++");t=1;break;}
    else if(str[n-1]=='c')
        {printf("c");p=1;break;}
    else if(str[i-3]=='j'&&str[i-2]=='a'&&str[i-1]=='v'&&str[i]=='a')
        {printf("java");q=1;break;}
    else
        {printf("none");break;}
    return 0;
}

猜你喜欢

转载自blog.csdn.net/m0_43382549/article/details/84310989