K
Kelly B
I would like to put the routine below in a function and call it whenever
i call scanf (in a code where i need multiple scanfs with different
number of arguments) I was wondering if it was possible to just pass the
number of arguments to the function and the function could parse the
desired no of arguments for me?
For example
if(num==1)
scanf()parses one integer
if(num==2)
scanf() parses two integers an so on...
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int test,res,ch,res1;
test=scanf_s("%d %d",&res,&res1);
while(test!=2)
{
while (('\n' != (ch = getchar())) && (EOF != ch));
puts("Enter an integer value");
test=scanf_s("%d %d",&res,&res1);
}
while (('\n' != (ch = getchar())) && (EOF != ch));
return 0;
}
i call scanf (in a code where i need multiple scanfs with different
number of arguments) I was wondering if it was possible to just pass the
number of arguments to the function and the function could parse the
desired no of arguments for me?
For example
if(num==1)
scanf()parses one integer
if(num==2)
scanf() parses two integers an so on...
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int test,res,ch,res1;
test=scanf_s("%d %d",&res,&res1);
while(test!=2)
{
while (('\n' != (ch = getchar())) && (EOF != ch));
puts("Enter an integer value");
test=scanf_s("%d %d",&res,&res1);
}
while (('\n' != (ch = getchar())) && (EOF != ch));
return 0;
}