//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]);
}
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 } }
Yes , printf is a library function . It is used to print something to standard output.
I could but I won't.
scanf is a function, not a statement. Example: int a; char name[12]; scanf ("%d %s", &a, &name[0]);
scanf: scanf is a built-in function to read input from the user.
stdio.h
Use '%s', eg: char name[64]; scanf ("%s", name);
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",&num);
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.
Yes: double d; printf ("scanf's just returned %d\n", scanf ("%lf", &d));
scanf is a function, not a statement. Example: int a; char name[12]; scanf ("%d %s", &a, &name[0]);
scanf: scanf is a built-in function to read input from the user.
stdio.h
Use '%s', eg: char name[64]; scanf ("%s", name);
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",&num);
Use the help/manual.
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 & 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.
Printf prints something to the standard output stream, and scanf inputs something from the standard input stream.
The scanf() function in the <stdio.h> C standard library header.
Your question makes no sense.