Is there is any function through which i can get specific number of integer like we do through getchar() funtion .I AM USING TURBO C 3.0.HELP WILL BE APPRECIATED.

Recommended Answers

All 10 Replies

How about you describe what you're trying to do? What you're asking for is somewhat nonsensical out of context.

try this

int num = getchar();

char myCharacter = 'A';
printf("%c = %d",myCharacter,myCharacter);

on further review, your question really doesnt make a lot of sense.

what are you asking?

You can always get integers using scanf functions.

you can use getw() & putw() functions to get integers from a file opened in binary mode.

Does this answer your question?

And also putw ( n = getw(stdin), stdout ) will seem to work but wont for a good reson. Find it of yourself by analyzing.

Actually the question is that i want to get a int array but dont specify how much i need in programme , like in getchar function can takes 0 to max size of an array , can i do it with int .

Example is this

char arr[100],i=0;

while((arr=getchar())!='\n')
i++;

so it will take any number of character from 0 to max size until enter is not encountered

but in integer i always want a loop any specific number

like

for(i=0;i<3;i++)
scanf("%d",&arr);

but my size of array can get 100 integer more and every time i want to come in main programme to specify how much i need

I think every one got it , so please help.

Why dont you loop it till the user inputs 0 or
till the scanf fails.
i.e., scanf ( "%d", addr ) ;
will scan data as far as it is valid inputs like 'x' when scanf expects integer are invaild & scanf will return 0.

Does this answer your question?

>so it will take any number of character from 0 to max size until enter is not encountered
Well, scanf doesn't recognize a newline, so you'll have to use some other method. A generally good one is to signal EOF when you're done by typing Ctrl+Z (Windows) or Ctrl+D (Unix/Linux), then this works:

int a[100];
int i;

for ( i = 0; i < 100; i++ ) {
  if ( scanf ( "%d", &a[i] ) == 0 )
    break;
}

>so it will take any number of character from 0 to max size until enter is not encountered
Well, scanf doesn't recognize a newline, so you'll have to use some other method. A generally good one is to signal EOF when you're done by typing Ctrl+Z (Windows) or Ctrl+D (Unix/Linux), then this works:

int a[100];
int i;

for ( i = 0; i < 100; i++ ) {
  if ( scanf ( "%d", &a[i] ) == 0 )
    break;
}

hey ,
if you are not looking to use any negative values in your array, I mean if you dont want your array to contain any negative value, then use -1 to termiate taking input for array

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.