Signup/Sign In

Answers

All questions must be answered. Here are the Answers given by this user in the Forum.

If you want it programatically, you could use
***
label.setTypeface(Typeface.SANS_SERIF, Typeface.ITALIC);
***
Where SANS_SERIF you can use:

-DEFAULT
-DEFAULT_BOLD
-MONOSPACE
-SANS_SERIF
-SERIF

And where ITALIC you can use:

-BOLD
-BOLD_ITALIC
-ITALIC
-NORMAL
4 years ago
Remark : in C++14 and as soon as the filesystem TS will be finished and adopted, the solution will be to use:
***
std::experimental::filesystem::exists("helloworld.txt");
***
and since C++17, only:
***
std::filesystem::exists("helloworld.txt");
***
4 years ago
"%f" is the (or at least one) correct format for a double. There is no format for a float, because if you attempt to pass a float to printf, it'll be promoted to double before printf receives it1. "%lf" is also acceptable under the current standard -- the l is specified as having no effect if followed by the f conversion specifier (among others).

Note that this is one place that printf format strings differ substantially from scanf (and fscanf, etc.) format strings. For output, you're passing a value, which will be promoted from float to double when passed as a variadic parameter. For input you're passing a pointer, which is not promoted, so you have to tell scanf whether you want to read a float or a double, so for scanf, %f means you want to read a float and %lf means you want to read a double (and, for what it's worth, for a long double, you use %Lf for either printf or scanf).
4 years ago
Put an l (lowercased letter L) directly before the specifier.
***
unsigned long n;
long m;

printf("%lu %ld", n, m);
***
4 years ago
There is no format specifier for bool. You can print it using some of the existing specifiers for printing integral types or do something more fancy:
***
printf("%s", x?"true":"false");
***
4 years ago
A static function is one that can be called on the class itself, as opposed to an instance of the class.

For example a non-static would be:
***
Person* tom = new Person();
tom->setName("Tom");
***
This method works on an instance of the class, not the class itself. However you can have a static method that can work without having an instance. This is sometimes used in the Factory pattern:
***
Person* tom = Person::createNewPerson();
***
4 years ago
Depends on what you want to do:

to read the value as an ascii code, you can write
***
char a = 'a';
int ia = (int)a;
/* note that the int cast is not necessary -- int ia = a would suffice */
***
to convert the character '0' -> 0, '1' -> 1, etc, you can write
***
char a = '4';
int ia = a - '0';
/* check here if ia is bounded by 0 and 9 */
***
Explanation:
a - '0' is equivalent to ((int)a) - ((int)'0'), which means the ascii values of the characters are subtracted from each other. Since 0 comes directly before 1 in the ascii table (and so on until 9), the difference between the two gives the number that the character a represents.
4 years ago
Print Binary for Any Datatype
***
// Assumes little endian
void printBits(size_t const size, void const * const ptr)
{
unsigned char *b = (unsigned char*) ptr;
unsigned char byte;
int i, j;

for (i = size-1; i >= 0; i--) {
for (j = 7; j >= 0; j--) {
byte = (b[i] >> j) & 1;
printf("%u", byte);
}
}
puts("");
}
***
Test:
***
int main(int argv, char* argc[])
{
int i = 23;
uint ui = UINT_MAX;
float f = 23.45f;
printBits(sizeof(i), &i);
printBits(sizeof(ui), &ui);
printBits(sizeof(f), &f);
return 0;
}
***
4 years ago
1. typedef is used to alias types; in this case you're aliasing FunctionFunc to void(*)().

2. Indeed the syntax does look odd, have a look at this:
***
typedef void (*FunctionFunc) ( );
// ^ ^ ^
// return type type name arguments
***
No, this simply tells the compiler that the *FunctionFunc* type will be a function pointer, it doesn't define one, like this:
***
FunctionFunc x;
void doSomething() { printf("Hello there\n"); }
x = &doSomething;
***
x(); //prints "Hello there"
4 years ago
signed char has range -128 to 127; unsigned char has range 0 to 255.

char will be equivalent to either signed char or unsigned char, depending on the compiler, but is a distinct type.

If you're using C-style strings, just use char. If you need to use chars for arithmetic (pretty rare), specify signed or unsigned explicitly for portability.
4 years ago
In (ANSI) C99, you can use a designated initializer to initialize a structure:
***
MY_TYPE a = { .flag = true, .value = 123, .stuff = 0.456 };
***
Other members are initialized as zero: "Omitted field members are implicitly initialized the same as objects that have static storage duration."
4 years ago
***
public class Printfiveloop {

public static void main(String[] args) {

System.out.println("Pattern is: ");
for(int number=0; number<=50; number++){

//check if number is multiple of 5
if(number%5==0){
System.out.print(number+" ");
}
}

}

}
***
4 years ago