Limit a specific value to a string

Asked

Viewed 39 times

-3

need to limit and a specific value that would be 511

char command[512];

I tried with

char command[512]; 
scanf("%511s",command);
if (StrToInt(command))>511)
printf("FIX ATK");

and that too

char command[512]; 
scanf("%511s", command);
if (strlen(command) > 511)
printf("FIX ATK");

and I didn’t succeed, someone knows how to solve?

  • Do you want the size entered to be less than 512? If so, what is the difficulty or problem? Or do you want to limit the number typed to less than 512? If so, why not ask for it as a number? This works: https://ideone.com/XtZAT9.

1 answer

-1

Good. Here you have to define if you want the value is less than 512

if (Strtoint(command))>511)

or if you want the string length is less than 512.

if (strlen(command) > 511)

Anyway, to convert string to integer, in c++, you should use Std::stoi.

I think you should explain your doubt better

Browser other questions tagged

You are not signed in. Login or sign up in order to post.