Jump to content

a little help at C

digitalMaster

how can i write this:

the user must give only integers

So i want to check if the numbers he is giving are integers.

(this is not the whole program)

 

 

a: my array where the user give the numbers

 

 

 

 

 

float x;

while (a[k]==x)
  printf("give an integer :   ");
   scanf("%d", &a[k]);
Link to comment
Share on other sites

Link to post
Share on other sites

What I usually do is let them input a string, then validate that the string only contains numbers and parse.

Link to comment
Share on other sites

Link to post
Share on other sites

Well if you look at the other thread you created the answer is in there (to an extent)

 

Anyways to address a few issues

int a[512];  //Given your assignment you must have an upper bounds (or just give it an upper bounds, as allowing indefinite input is way beyond your current comprehension)

So this is your a array declaration (no like your previous post a, this is invalid)

 

If the user enters the amount of numbers he is going to enter (less correct way, but apparently it will compile under newer standards...I don't compile with this kind of code so I could be wrong)

scanf("%d", &i);

int a;

0b10111010 10101101 11110000 00001101

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×