if(stricmp(ext,".doc")==0)
return 1;
else if(stricmp(ext,".xls")==0)
return 2;
else if(stricmp(ext,".dwg")==0)
return 3;
else if(stricmp(ext,".psd")==0)
return 4;
else if(stricmp(ext,".pdf")==0)
return 5;
else if(stricmp(ext,".txt")==0)
{
// m_listCtrl.InsertItem(0,"txt");
return 6;
}
else
return 0;
如果上面的被注释的语句没有注释掉,则返回值正常
否则当ext=".txt"时返回0……

解决方案 »

  1.   

    #include "stdio.h"
    #include "string.h"
    int checkext(char *ext);
    main()
    {
    char *p=".dwg";
    printf("%d\n",checkext(p));
    char buf[4];
    printf("请输入扩展名:");
    scanf("%s",buf);
    printf("%d\n",checkext(buf));
    getchar();
    return 0;
    }
    int checkext(char *ext)
    {
    int i;
    if(stricmp(ext,".doc")==0)
    i=1;
    else if(stricmp(ext,".xls")==0)
    i=2;
    else if(stricmp(ext,".dwg")==0)
    i=3;
    else if(stricmp(ext,".psd")==0)
    i=4;
    else if(stricmp(ext,".pdf")==0)
    i=5;
    else if(stricmp(ext,".txt")==0)
    i=6;
    else
    i=0;
    return i;
    }
    这是我写的测试代码,可以正确返回,但是我在程序里用的时候选择1 2 都可以正常返回,选择6时则返回0。
      

  2.   

    底下的测试程序是对的,上面的程序在实际应用时,当ext=".txt"时返回错误。