The strncpy works fine but the conversion to integer doesnt work.
Basically what im trying to do is my input to the function is under this format:
or
Code:
530 Login or password incorrect!
I want to simply isolate and return the integer (220 or 530)
for now this function manages to isolate the number but only as a string (txt)
Code:
int returnCode(char * buf) {
char txt[4] = "123";
char *ptr;
printf("----%s",buf);
strncpy(txt,buf,3);
printf("----%3s",txt);
long i = strtol(txt,&ptr,4);
printf("\n%li\n",i);
return 0 ; /* value for compile*/
};
here the value of txt is perfect but whenever i use strtol i becomes 0 instead of becoming that number. what am i missing in the strtol to make it work.