How to count numbers from string ?

code:

#include<stdio.h>
#include<stdlib.h>
int main(){

char line[]="1 -2 10000 -50 20 7 445 -4";
char *p,*e;
long input;
int counts =0;
p=line;
for(p=line; ;p=e)
{
    input = strtol(p,&e,10);
    if(p==e)
    {
     break;
    }
    counts++;
}
printf("%d\n",counts);

return 0;
}

 

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published.