answersLogoWhite

0


Best Answer

//program for myprintf using variable arguments

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

#include <stdarg.h>

int compare(const void * var1,const void * var2)

{

if(*(int *)var1 > *(int *)var2)

{

return(0);

}

else{

return(1);

}

}

int myPrintf(const char * output ,...)

{

va_list arguments;

int stringlength,stringIndx;

char *s;

int d;

char c;

stringlength = strlen(output);

va_start(arguments,output);

for(stringIndx = 0;stringIndx < stringlength;stringIndx++)

{

if(output[stringIndx] == '%')

{

stringIndx++;

switch(output[stringIndx])

{

case 's': /* string */

s = va_arg(arguments, char *);

printf("%s\n", s);

break;

case 'd': /* int */

d = va_arg(arguments, int);

printf("%d\n", d);

break;

case 'c': /* char */

default:

/* need a cast here since va_arg only

takes fully promoted types */

c = (char) va_arg(arguments, char);

printf("%c\n", c);

break;

}

}

else{

printf("%c",output[stringIndx]);

}

}

}

void main()

{

unsigned int au32Nos[10] = {32,44.,55,66,11,8,9,7,9,10};

qsort(au32Nos,10,4,compare);

myPrintf(" %d %d %d %d %d %d %d %d %d %d",au32Nos[0],au32Nos[1],au32Nos[2],au32Nos[3],au32Nos[4],au32Nos[5],au32Nos[6],au32Nos[7],au32Nos[8],au32Nos[9]);

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

15y ago

we can use va_start, va_end, va_list printf(char fmt,...) { va_list ptr; // ptr is pointer implicit switch(fmt) { case s: va_start(ptr); putch(ptr); // fmt is for s d f and all } }

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

Yes , printf is a library function . It is used to print something to standard output.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

I could but I won't.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can you write a function similar to scanf?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Is there a function similar to the C plus plus scanf function in JavaScript?

Scanf is part of the C standard library. Although the C++ standard library includes 18 headers from the ISO C90 standard, their usage in C++ is deprecated. However, to answer the question, there is no equivalent to scanf in JavaScript.


Can you use scanf function within printf function?

Yes: double d; printf ("scanf's just returned %d\n", scanf ("%lf", &amp;d));


Why not use the ampression symbol in scanf statement in function?

scanf is a function, not a statement. Example: int a; char name[12]; scanf ("%d %s", &amp;a, &amp;name[0]);


What is the syntax of scanf?

scanf: scanf is a built-in function to read input from the user.


What are the header file of scanf function?

stdio.h


Scanf function in c for strings?

Use '%s', eg: char name[64]; scanf ("%s", name);


What is scanF function?

scanf() is an input function which reads input from the standard input devices such as keyboard. Syntax: scanf("Control Character",address_list); where control character is a sequence of one or more character such as %d,%f,%lf,%lld. Address list specifies the variables, pointers etc. e.g. scanf("%d",&amp;num);


What is return type of scanf function?

Use the help/manual.


Difference between cin and scanf?

the getchar function waits the user hit a key followed by return key. Upon the return key hitted by the user the function returns the key. But the scanf can be used for various &amp; different user entered data including text, integer, float and so on. in spite of getchar the delimeter keys for scanf function are tab, space and return key; so when a space entered by the user in the input the scanf will end the input and waits user enter the return key. You must take in mind that just the fragment of input that is behind these delimeters will be considered as legal input for the scanf and the remaninder will be escaped.


What is the use of printf and scanf function?

Printf prints something to the standard output stream, and scanf inputs something from the standard input stream.


Which function is used to read data from the console?

The scanf() function in the &lt;stdio.h&gt; C standard library header.


Is scanf function follow the que or stack operation?

Your question makes no sense.