T
Tarique
I have tried to write my custom scanf function on the lines of minprintf
provided in K&R2.In the function myscanf() i access memory directly
using the address passed to the function .Can it be dangerous ?
I am getting the correct output though.Any help is appreciated.
/*Include Files*/
/*Assisting Functions*/
int flushln(FILE *f){ /*Code*/}
char *input(char *message){/*Code*/}
static int getInt(void){/*Code*/}
/*My Custom Scanf Routine*/
int myscanf(const char* format,...)
{
va_list ap;
const char *p;
int count = 0;
int temp;
va_start(ap,format);
for( p = format ; *p ;p++) {
if( *p != '%'){
continue;
}
switch(*++p){
case 'd':
if(temp = getInt()){
*(long *)va_arg(ap,int) = temp;/*Direct Memory Access*/
count ++;
}
else{ puts("Input Error"); }
break;
}
}
va_end(ap);
return count;
}
int main(void)
{
int a = 0,b = 0;
myscanf("%d %d",&a,&b);
printf("%d %d",a,b);
return 0;
}
Thanks!
provided in K&R2.In the function myscanf() i access memory directly
using the address passed to the function .Can it be dangerous ?
I am getting the correct output though.Any help is appreciated.
/*Include Files*/
/*Assisting Functions*/
int flushln(FILE *f){ /*Code*/}
char *input(char *message){/*Code*/}
static int getInt(void){/*Code*/}
/*My Custom Scanf Routine*/
int myscanf(const char* format,...)
{
va_list ap;
const char *p;
int count = 0;
int temp;
va_start(ap,format);
for( p = format ; *p ;p++) {
if( *p != '%'){
continue;
}
switch(*++p){
case 'd':
if(temp = getInt()){
*(long *)va_arg(ap,int) = temp;/*Direct Memory Access*/
count ++;
}
else{ puts("Input Error"); }
break;
}
}
va_end(ap);
return count;
}
int main(void)
{
int a = 0,b = 0;
myscanf("%d %d",&a,&b);
printf("%d %d",a,b);
return 0;
}
Thanks!