-4

Scenario :-

My array contains elements like 56,12,ew34,45 or 56,12,34rt,45 how can I show that the array is not integer array?

var Array =[56,12,'ew34',45 or 56,12,'34rt',45];

Actually am trying to find a solution with out Inbuilt Functions.

Prasad
  • 1,562
  • 5
  • 26
  • 40
reciever
  • 69
  • 2
  • 11
  • What is the data type of the array? – Pang Mar 05 '16 at 05:50
  • Is the array declared as an array of integers? Then it contains only integers. It would help if you could be more specific, like telling us *what* the array is, to show us its declaration. – Some programmer dude Mar 05 '16 at 05:50
  • An integer array, by definition, cannot contain anything other than integers. Perhaps you are asking whether any of the integers in the array are in the valid range for ASCII characters? – merlin2011 Mar 05 '16 at 05:50
  • data type of the array is integer.If I input any characters other than integers it should return 0 else return 1.@Pang – reciever Mar 05 '16 at 05:54
  • 2
    It sounds like you are trying to detect character sequences (strings) that look like integers. Please show us what you have already tried. – merlin2011 Mar 05 '16 at 05:55
  • Hi, I suppose that you create an char array to store the input from user (via console or sth else), and then you need to check whether the input contains non-numeric char. If this assumption is correct, you should check the function strtol [link](http://man7.org/linux/man-pages/man3/strtol.3.html) – vad Mar 05 '16 at 06:00
  • 1
    Did you mean... `if ( ( ret = scanf("%d", &arr[i]) ) != 1 ) return (0) ;` ? – mauro Mar 05 '16 at 06:03
  • @mauro +1 That seems what OP's looking for. – eca2ed291a2f572f66f4a5fcf57511 Mar 05 '16 at 06:04
  • I tried this @merlin2011: arr = (int*)malloc(sizeof(int)*len); for (i=0; i < len; i++) { if (scanf("%d", &arr[i] !=1)) return NULL; } where len is any integer.(let len=5) Now,I enter some elements like 24,34,r23,5k,99 and I should return 0 as there are non-inegers like r23 and 5k. – reciever Mar 05 '16 at 06:04
  • 2
    http://stackoverflow.com/help/how-to-ask -- please refer it before posting your Query – Prasad Mar 05 '16 at 06:04
  • @nikhilkumar What you're looking for is already covered by scanf. All you need to do is to check if scanf returns a zero, which means that things other than integers are detected and that scanf cannot further proceed. – eca2ed291a2f572f66f4a5fcf57511 Mar 05 '16 at 06:07
  • You already seem to check for non-integers in your reading loop (please edit your question to include such information), so I don't really see the problem (except the memory leak and the syntax error you have from re-writing the code in your comment). Can you please edit your question to elaborate on the problem you have with the code you tried? – Some programmer dude Mar 05 '16 at 06:20
  • got it.thanks every one :) – reciever Mar 06 '16 at 08:27

1 Answers1

0

If array is declared as integer type then it won't accept any char type data. If you are trying to insert 0 instead of char type data, handle the same conveniently at the insertion time. Also you can make use of compiler extension typeof.

Community
  • 1
  • 1
SKR
  • 21
  • 4