How to Compare Last n Characters of A String to Another String in C

后端 未结 6 1546
野性不改
野性不改 2021-01-02 07:41

Imagine that I have two strings, one of them is a url like \"/sdcard/test.avi\" and the other one is\"/sdcard/test.mkv\". I want to write an if statement that looks whether

6条回答
  •  春和景丽
    2021-01-02 08:17

    #include 
    #include 
    
    int main(void)
    {
        DIR *dir;
        struct dirent *ent;
        char files[100][500];
        int i = 0;
    
        memset(files, 0, 100*500);
        dir = opendir ("/sdcard/");
        if (dir != NULL)
        {
            /* Print all the files and directories within directory */
            while ((ent = readdir (dir)) != NULL)
            {
                strcpy(files[i], ent->d_name);
                if(strstr(files[i], ".avi") != NULL)
                {
                    printf("\n files[%d] : %s is valid app file\n", i, files[i]);
                    i++;
                }
            }
            closedir (dir);
        }
        return 0;
    }
    

提交回复
热议问题