How to convert a string to a integer in C

CServer Side ProgrammingProgramming

First extract characters from left bracket '(' using strchr() function.

char *name="The Matrix(1999)";
char *ps;
ps=strchr(name,'(');

Then add each character within brackets () to an char array

char y[5]=""; int  p;
for (p=1;p<strlen(ps+1);p++) {
   y[p-1]=ps[p];
}
y[4]='\0';

Lastly convert resultant string to integer using atoi() function

year=atoi(y);
printf("year=%d",year);

You can now apply required filters ti create array of strings of all movies prior to 2008

raja
Published on 08-May-2018 14:28:46
Advertisements