Question d’entretien chez NVIDIA

Substring function

Réponses aux questions d'entretien

Utilisateur anonyme

6 mars 2012

Brute force accepted

1

Utilisateur anonyme

8 juin 2012

This function return 0 when the sub string was not found at the given string or unsigned integer number bigger then 0, which indicate the number of occupancy. int my_strstr(const char* str, const char* to_find){ static int num_of_occur = 0; while (*str) { const char* tmp_s = str; const char* tmp_f = to_find; while ( (*tmp_f == *tmp_s) && *tmp_f) { tmp_f++; tmp_s++; } if(!(*tmp_f)) num_of_occur++; str++; } return num_of_occur; }

1