Signup/Sign In

Answers

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

A static function in C is a function that has a scope that is limited to its object file. This means that the static function is only visible in its object file. A function can be declared as a static function by placing the static keyword before the function name.

A program that demonstrates static functions in C is given as follows ?


*Example*

***#include

static void staticFunc(void){
printf("Inside the static function staticFunc() ");
}

int main()
{
staticFunc();
return 0;
}***


*Output*

The output of the above program is as follows ?

***Inside the static function staticFunc()***

In the above program, the function **staticFunc()** is a static function that prints ”Inside the static function **staticFunc()**”. The **main()** function calls **staticFunc()**. This program works correctly as the static function is called only from its own object file.
4 years ago
In case anyone wants the answer of Dirk Vollmar in a C# switch statement:
***case "doc": return "application/msword";
case "dot": return "application/msword";
case "docx": return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
case "dotx": return "application/vnd.openxmlformats-officedocument.wordprocessingml.template";
case "docm": return "application/vnd.ms-word.document.macroEnabled.12";
case "dotm": return "application/vnd.ms-word.template.macroEnabled.12";
case "xls": return "application/vnd.ms-excel";
case "xlt": return "application/vnd.ms-excel";
case "xla": return "application/vnd.ms-excel";
case "xlsx": return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
case "xltx": return "application/vnd.openxmlformats-officedocument.spreadsheetml.template";
case "xlsm": return "application/vnd.ms-excel.sheet.macroEnabled.12";
case "xltm": return "application/vnd.ms-excel.template.macroEnabled.12";
case "xlam": return "application/vnd.ms-excel.addin.macroEnabled.12";
case "xlsb": return "application/vnd.ms-excel.sheet.binary.macroEnabled.12";
case "ppt": return "application/vnd.ms-powerpoint";
case "pot": return "application/vnd.ms-powerpoint";
case "pps": return "application/vnd.ms-powerpoint";
case "ppa": return "application/vnd.ms-powerpoint";
case "pptx": return "application/vnd.openxmlformats-officedocument.presentationml.presentation";
case "potx": return "application/vnd.openxmlformats-officedocument.presentationml.template";
case "ppsx": return "application/vnd.openxmlformats-officedocument.presentationml.slideshow";
case "ppam": return "application/vnd.ms-powerpoint.addin.macroEnabled.12";
case "pptm": return "application/vnd.ms-powerpoint.presentation.macroEnabled.12";
case "potm": return "application/vnd.ms-powerpoint.template.macroEnabled.12";
case "ppsm": return "application/vnd.ms-powerpoint.slideshow.macroEnabled.12";
case "mdb": return "application/vnd.ms-access";***
4 years ago
You can use **iconv** command under Unix (also available on Windows as **libiconv**).

After saving as CSV under Excel in the command line put:

***iconv -f cp1250 -t utf-8 file-encoded-cp1250.csv > file-encoded-utf8.csv***
(remember to replace cp1250 with your encoding).

Works fast and great for big files like postcodes database, which cannot be imported to GoogleDocs (400.000 cells limit).
4 years ago
One interesting way is by using array_keys():

***foreach (array_keys($messages, 401, true) as $key) {
unset($messages[$key]);
}***
The **(array_keys()** function takes two additional parameters to return only keys for a particular value and whether strict checking is required (i.e. using === for comparison).

This can also remove multiple array items with the same value (e.g. [1, 2, 3, 3, 4]).
4 years ago
**~version** “Approximately equivalent to version”, will update you to all future patch versions, without incrementing the minor version. ~1.2.3 will use releases from 1.2.3 to <1.3.0.

**^version** “Compatible with version”, will update you to all future minor/patch versions, without incrementing the major version. ^2.3.4 will use releases from 2.3.4 to <3.0.0.
4 years ago
We can use the minimist library.

Here is an example of how to use it taken straight from the minimist documentation:

***var argv = require('minimist')(process.argv.slice(2));
console.dir(argv);***
-

***$ node example/parse.js -a beep -b boop
{ _: [], a: 'beep', b: 'boop' }***
-

***$ node example/parse.js -x 3 -y 4 -n5 -abc --beep=boop foo bar baz
{ _: [ 'foo', 'bar', 'baz' ],
x: 3,
y: 4,
n: 5,
a: true,
b: true,
c: true,
beep: 'boop' }***
4 years ago
The org.json library is easy to use.

Just remember (while casting or using methods like getJSONObject and getJSONArray) that in JSON notation

[ … ] represents an array, so the library will parse it to JSONArray
{ … } represents an object, so the library will parse it to JSONObject
Example code below:

***import org.json.*;

String jsonString = ... ; //assign your JSON String here
JSONObject obj = new JSONObject(jsonString);
String pageName = obj.getJSONObject("pageInfo").getString("pageName");

JSONArray arr = obj.getJSONArray("posts"); // notice that `"posts": [...]`
for (int i = 0; i < arr.length(); i++)
{
String post_id = arr.getJSONObject(i).getString("post_id");
......
}***
You may find more examples from Parse JSON in Java
4 years ago
Use like this.

***List stockList = new ArrayList();
stockList.add("stock1");
stockList.add("stock2");

String[] stockArr = new String[stockList.size()];
stockArr = stockList.toArray(stockArr);

for(String s : stockArr)
System.out.println(s);***
4 years ago
For sorting an ArrayList you could use the following code snippet:

***Collections.sort(studList, new Comparator(){
public int compare(Student s1, Student s2) {
return s1.getFirstName().compareToIgnoreCase(s2.getFirstName());
}
});***
4 years ago
A **wait** can be "woken up" by another thread calling **notify** on the monitor which is being waited on whereas a **sleep** cannot. Also, a **wait** (and **notify**) must happen in a block **synchronized** on the monitor object whereas **sleep** does not:

***Object mon = ...;
synchronized (mon) {
mon.wait();
} ***
At this point, the currently executing thread waits and releases the monitor. Another thread may do

***synchronized (mon) { mon.notify(); }***
4 years ago
*For Java Version 9 or higher versions*

***// this works for up to 10 elements:
Map test1 = Map.of(
"a", "b",
"c", "d"
);

// this works for any number of elements:
import static java.util.Map.entry;
Map test2 = Map.ofEntries(
entry("a", "b"),
entry("c", "d")
);***

*For up to java 8 versions*

***Map myMap = new HashMap() {{
put("a", "b");
put("c", "d");
}};***
4 years ago
**size_t** is a type that can hold any array index.

Depending on the implementation, it can be any of:

unsigned char

unsigned short

unsigned int

unsigned long

unsigned long long

Here's how size_t is defined in stddef.h of my machine:

***typedef unsigned long size_t;***
4 years ago