Hi,guys!
I would like to ask you : How to find out how much numbers are in array except space? My program will find out length of array, until user input will be space and that is the problem. So if I have inserted "10 20 300", the length will be 2. I have expected 3,like three numbers,which were inserted.And I don't know,how much numbers will user type in. I have already tried strlen(p),it was the same thing. Can you help me? Thanks!
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char p[1000];
char val[1000];
int length = 0;
char* itr;
fgets(p, sizeof(p), stdin);
itr = strtok(p, " ");
while(itr!=NULL)
{
val[length]=atof(itr);
itr = strtok(NULL, "");
length ++;
}
itr = strtok(p, " \n");
printf("%d",length);
return 0;
}