This works.
#include <string>
#include <iostream>
using namespace std;
int main() {
char title[20] = "testmovie2015.mkv";
int year=0,i=0;
for(i=0;title[i]!='\0';i++){
if(isdigit(title[i])&&isdigit(title[i+1])&&isdigit(title[i+2])&&isdigit(title[i+3]))
{ year=1;
break;
}
}
if(year)
{
year=((title[i]-'0')*1000)+((title[i+1]-'0')*100)+((title[i+2]-'0')*10)+(title[i+3]-'0');
if(year>=2000&&year<=2018)
{ int k=0;
while(k<i)
{
cout<<title[k];
k++;
}
}
else
{
cout<<"Year found: "<<year<<", but out of given range";
}
}
else
{
cout<<"No year found in the string";
}
}
3
solved Find loop value inside string