w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
keyboard events, char counter and textLength prop dilemma
Using the input event will get what you want. See this fiddle. It will fire AFTER the value has changed, but continually while the user presses or holds a key.

Categories : Javascript

Problem to plot 3D surface with R‏
Try this to see why I don't think this data is well suited for wireframe: cloud(Z~X+Y, data=FI02, xlab="X", ylab="Y", main="Surface elevation", type="l", screen=list(z=-60, x=-60))

Categories : R

kruskal.test shows "All group levels must be finite" error. What is the problem?
It should work if you run data$Grp <- as.factor(data$Grp) Then (as before): kruskal.test(data$Val, data$Grp) This is because Grp is a character not a factor and is.finite applied to an object of character class is always false (see ?is.finite).

Categories : R

Does truncating a counter column family have the same caveats as removing a single counter
The issue is the same: if you are doing simultaneous deletes or truncates and increments, the result is undefined. The issue is that delete is effectively setting the counter value to zero. Truncate is setting all counter values to zero. The 'set' operation does not commute with the 'inc' operation, so a mixture of simultaneous operations gives unpredictable results. If you aren't doing increments or can pause them, then it is perfectly safe doing a truncate. There is no need to drop the column family. If you cannot stop the increments then it depends on your client. Dropping the column family will cause the client to fail until it is recreated - if the client can survive those errors and then continue that might work. But the best would be to temporarily pause the increments.

Categories : Cassandra

The requested Performance Counter is not a custom counter, it has to be initialized as ReadOnly." on RouteTable.Routes.MapHubs();
So based on the information you've provided it is clear that these are first chance exceptions being thrown when SignalR is attempting to create the performance counters but doesn't have the rights to do so with the identity that the process is running under. You can safely ignore these exceptions, but you obviously won't get performance counter data. If you want to create the performance counters you need to make sure the identity of your application belongs to the Performance Counter Users group when it's running. Either that or you need to use the utility application provided in the Microsoft ASP.NET SignalR Utilities NuGet package that allows you to create the counters out of band. Just install the package and run the command: signalr ipc

Categories : C#

Getting "The requested Performance Counter is not a custom counter, it has to be initialized as ReadOnly." while trying to self-host SignalR with Owin
While I cannot explain why this happens, in my experience it is not a fatal error. See for example the response to this issue. Therefore I would suggest that you ignore the exception and hope that if a further exception occurs that provides further insight into your underlying problem.

Categories : C#

Hadoop difference between methods Counter.getName and Counter.getDisplayName
getName returns the name of the counter getDisplayName() returns the user facing name of the counter Source : http://hadoop.apache.org/docs/r2.0.3-alpha/api/org/apache/hadoop/mapreduce/Counter.html#getName()

Categories : Java

How to set constantly incrementing counter in javascript , to perform another operation when counter > certain value?
Use function memoization to avoid global "timer" variables: function run(){ run.timer = run.timer || 0; return run.timer++; } // run ends here setInterval(run,1000); And to act accordingly to the timer, run your handling from run(), for example: function run(){ run.timer = run.timer || 0; run.timer = handleTimer(run.timer++); } // run ends here setInterval(run,1000); function handleTimer(timer) { if(timer > 5){ $("iframe").hover(function(){ $.ajax({ url: 'http://localhost/test.html', cache: false, data: 'html', success: function(data,status) { } }); // And disable hover handler once executed $("iframe").unbind("mou

Categories : Javascript

is char** x = (char**) arg equivalent to reinterpret_cast(const_cast(arg) )?
Yes they are basically the same except the c++ style cast shows the reader of the code that you are doing some weird stuff while its harder to notice with the c style. Its legal yet as always its highly suspect when a const incoming parameter is being cast as non const.

Categories : C++

Templatized ostream overload ambiguity error : basic_ostream vs const char[]
The non-template operator does not cause any ambiguity because that operator itself is not viable for resolving this call: return out << "a1"; // ^^^^^^^^^^^ // This MUST be `std::operator <<`, no other valid overload of // operator << is found! As well as the other similar ones. The template version, on the other hand, is viable, since T is not bound to be any concrete type: template <class T> ostream& operator<<(ostream& out, const T& a) { switch(a) { case T::a1 : return out << "a1"; // ^^^^^^^^^^^ // Here the compiler could invoke std::operator << // OR it could invoke your operator << template, // which is also viable since T could be anything! //

Categories : C++

Unable to pass an address of array of type char *[2] to function taking char ***
char *array[2] = {"string", "value"}; is an array with 2 elements of char *. Using array as an address results to a pointer to the first element, i. e. of type char **. Using &array results to a pointer to the same place, but of type char *(*)[2] (not sure if the spelling is right). This is not the same as a char *** - the representation in memory is completely different. To be more verbose, +++++++++++++++++++++++ + array[0] + array[1] + +++++++++++++++++++++++ this is the array. char ** p1 = array; // is a pointer to the first element, which in turn is a pointer. char *(*p2)[2] = &array; // is a pointer to the whole array. Same address, but different type, i. e. sizeof(*p1) != sizeof(*p2) and other differences. char ***p3 = &p1; // Now, p1 is a different pointer va

Categories : C

char pointers, char arrays, and strings in the context of a function call
The char[] signature in the parameter is exactly the same as char*. In C++, it is illegal to convert a string constant char const* (the string "Kacy") to a char* because strings are immutable. Your second example compiles because the name is an actual array. There is no change to char*. As a solution, change your parameter to take a const string array: Student(char const name[]); which again is the same as String(char const *name); though you're better off using std::string: #include <string> class String { public: String(std::string name); };

Categories : C++

C - Sort char string in array to equal char user input
OK, so basically you want to convert a sorted array of letters to a specific (random?) ordering and record the swaps along the way, right? Here is one way to do this. #define SWAP(a,b) a^=b;b^=a;a^=b int main(int argc, char* argv[]) { char* wordInput=argv[1]; char* newWord = (char*)malloc((strlen(wordInput) + 1) * (sizeof(char))); int i,j,k; fprintf(stdout, "Word is %s ", wordInput); // Sort wordInput into newWord. for (i=0; i<strlen(wordInput); i++) { // Put this one at the end. newWord[i]=wordInput[i]; // Start at the back of the string, and move it forward if it is less. for (j=i-1; j>=0; j--) { if (newWord[j+1] < newWord[j]) { SWAP(newWord[j+1], newWord[j]); } else { break; } } } newWord[strlen(wordInput)]

Categories : C

How to disable type char in JTextArea but enable removed char (Backspace)
try to put DocumentFilter instead of DocumentListener something like final AbstractDocument abstractDocument = (AbstractDocument) textArea.getDocument(); abstractDocument.setDocumentFilter(new DocumentFilter() { @Override public void remove(final FilterBypass fb, final int offset, final int length) throws BadLocationException { super.remove(fb, offset, length); } @Override public void insertString(final FilterBypass fb, final int offset, final String string, final AttributeSet attr) throws BadLocationException { if (getLineCountAsSeen(textArea) < 4) { super.insertString(fb, offset, string, attr); }

Categories : Java

How can I write a function boolean succeeds(char a, char b, String s)? using s.equals(""), s.charAt(0), s.substring(1)
Something like this should work. I have not compiled this. Hopefully it gets you in the right direction, even with possible syntax errors. public boolean succeeds(char a, char b, String s){ boolean sawFirst= false; for(int i=0;i<s.length();i++){ if(!sawA){ if(s.charAt(i)==b) sawFirst = true; } else{ if(s.charAt(i)!=a) return false; else sawFirst= false; } } return true; }

Categories : Java

How compare a char / single char string - with some list of alphabets set
If the starting letter is always an English character (or anything representable by a reasonably small integer that fits into an unsigned char), then here's a solution (the fastest possible one I can think of - uses no jumps except for the first check for initialization and only plain old integers are used instead of the somewhat heavier-weight comparison of NSString instances): - (UIColor *)colorFromName:(NSString *)name { static UIColor *strs[1 << CHAR_BIT] = { nil }; static BOOL initted = NO; if (!initted) { strs['a'] = [UIColor greyColor]; strs['b'] = [UIColor whiteColor]; // ... strs['z'] = [UIColor blueColor]; initted = YES; } unsigned char first = tolower([name characterAtIndex:0]); return strs[first]; }

Categories : IOS

What to call method which returns char* ( String in Java and char* in C++)?
It returns a String object and you can use the JNI string functions to convert that string to a char*: char* gPGGetName() { jobject objStr = env->CallObjectMethod(g_Obj, g_s3eGPGGetName); jsize len = env->GetStringUTFLength(objStr); const char* strPtr = env->GetStringUTFChars(objStr, 0); char* buffer = (char*)malloc((len + 1) * sizeof(char)); memcpy(buffer, strPtr, len); buffer[len] = ''; env->ReleaseStringUTFChars(objStr, strPtr); return buffer; }

Categories : Android

Printing the memory representation of an integer using char* and unsigned char*
This is because (on your system) char is signed, and it's getting promoted to int in the printf() call. Use unsigned char: void print_bytes(const unsigned char *ptr, size_t len) { for(size_t i = 0; i < len; ++i) { printf("%p %x ", ptr + i, ptr[i]); } }

Categories : C

Why does GCC accept convertion from 'const char *' to 'char *' on std::strrchr() returned value?
Actually your g++ does not accept the conversion from 'const char *' to 'char *', it's just that on your version std::strrchr() returns a char* (incorrectly, instead of a const char*). To verify the first part of my statement, try to compile the following on your GCC versions, I predict that all will correctly issue an error: int main() { const char* p = "foo"; char* q = p; // error, invalid conversion from 'const char*' to 'char*' } Now for the second part, I tried to compile the following minimal code, whose actual aim is to trigger an error in order to list the declared overloads of std::strrchr: #include <cstring> void (*p)() = &std::strrchr; // error here, with "candidates are: ..." int main() {} Well, with gcc 4.7.2 the message shows the expected "all non-c

Categories : C++

Regarding type safety when storing an unsigned char value in char variable
"does this mean that char could maintain its 'signedness' throughout the comparison?" yes; -1 as a signed char will be promoted to a signed int, which will retain its -1 value. As for the unsigned char, it will also keep its 255 value when being promoted, so yes, the comparison will be false. If you want it to evaluate to true, you will need an explicit cast.

Categories : C

Using SWIG to convert C++ char* as char[] in Java instead of String
To do this you'll need to replace the default SWIG supplied typemaps with one of your own. The simplest way to do this requires just writing some Java "glue": %module test %typemap(jstype) char *to_cstring() "byte[]"; %typemap(javaout) char *to_cstring() { return $jnicall.getBytes(); } %inline %{ char *to_cstring() { static char ret[] = "hello world"; return ret; } %} Does exactly what you want by calling getBytes() behind the scenes on the default returned String. You can also do this with some JNI of your own to return it as a byte array all the way through from your native code: %module test %typemap(jstype) char *to_cstring() "byte[]"; %typemap(jtype) char *to_cstring() "byte[]"; %typemap(javaout) char *to_cstring() { return $jnicall; } %typemap(jni) char *to_cstring()

Categories : C++

Adding string, char by char, into a 2dim array
Why does it know to do this? Because in C and C++, elements of an array are laid out contiguously in memory. Multidimensional arrays are simply arrays of arrays, and so are also contiguous. So when you write past the first row of your array, it simply keeps writing into memory and happens to get to the next row, since that next row is next up in the memory. What you can do is the following, if you want to do bounds checking: const int ROW = 5; const int COL = 5; char arr[ROW][COL] = {0}; for (int i = 0; i < new_keyword.length() && i < ROW * COL; i++) (&arr[0][0])[i] = new_keyword[i]; for (int i = 0; i < new_alphabet.length() && i + new_keyword.length() < ROW * COL; i++) (&arr[0][0])[new_keyword.length() + i] = new_alphabet[i]; Or, as Hello

Categories : C++

how to convert c++ char read using "Marshal.ReadByte" to c# char?
Assuming the source char is using ASCII or Latin-1 (ISO 8859-1), in C# you'd do char ch = (char)Marshal.ReadByte(...);. This works because the ASCII and Latin-1 encodings are subsets of Unicode. A .NET char is a UTF-16 code unit, which will fit each of these fine with just a cast. If you think you'll deal with other source encodings, a better option may be to use Encoding.GetString() on a byte array. Keep in mind that some encodings require multiple units to encode a single code point (UTF-8, EUC-JP, Shift-JIS, etc.), so a single char may not be enough.

Categories : C#

How do I convert a char to a char-based Enum object?
Your "sloppy" solution seems entirely appropriate to me. There's nothing else which is going to default to "undefined" for you. Using the conditional operator would make it slightly cleaner: private static OptionalityEnum Convert(char ch) { OptionalityEnum result = (OptionalityEnum)ch; return Enum.IsDefined(typeof(OptionalityEnum), result) ? result : OptionalityEnum.undefined; } EDIT: For the TryConvert method, I'd actually make sure that you set opt to default(OptionalityEnum) if it doesn't exist. But no, I don't believe this exists in the framework. However, you might want to look at my Unconstrained Melody project where you could at least use the IsNamedValue extension method, which would avoid boxing.

Categories : C#

Unhandled Exception when converting const char to char
Both your contents of buff and buffA are in read-only memory of the process. You will actually need to new your buff like char* buff = new char[32]; This provides memory from the free-store and you can then strcat the string from buffA to buff. You should prefer strncat, though to avoid buffer-overruns and delete your buff eventually.

Categories : C++

Java regex : matching a char except when preceded by another char
You need a negative lookbehind for that: String.Split("(?<![\\]);"); Here is a demo on ideone.

Categories : Java

Why doesn't C function with char** param set value of a pointer to char[] arg
The problem is that a pointer to an array is not compatible with a pointer to a pointer. They are different things. And it's a good thing too, because this is meant to catch errors like the one in your code. What you are doing is basically this: unsigned char szrecordid[28]; szrecordid = malloc(i * sizeof **value); You should be able to see the problem; you're trying to assign a pointer to an array.

Categories : C

Cannot invoke equals(char) on the primitive type char
Primitives are compared with ==. If you convert the chars to the wrapper classes Character, then you can use .equals(). Either change char guess; to Character guess; or if(guess.equals(wordContainer[j])) to if(guess == wordContainer[j])).

Categories : Java

Seg faulting on a car cast from unsigned char to const char in C++
Note that you cannot initialize a char* from a string literal in C++11. The clause which allowed that initialization in C++98 and C++03 was removed. If you worked out why that is, you have a hint on one thing which went wrong! You may want to read up on memory allocation as well or, better yet, use proper C++ facilities like std::string as raw pointer manipulators are fairly hard to get right.

Categories : C++

why does passing char[] not work, but (deprecated conversion) char* does?
You have a problem in that you store pointers to local variables in the structure. In the case of the test_char2 array, it no longer exists once the get_struct function returns. This means that the pointer a_char2 no longer points to a valid string, and dereferencing this pointer is undefined behavior. The reason the first pointer works, is because it doesn't point to a local variable, it points to a string literal, and those are stored elsewhere in memory. When coding in C++, there is no longer a reason to use pointers or arrays for string, instead use the std::string class.

Categories : C++

Java Error, required: char[] found char
The posted sample works if your target variable is of type char, so I assume that you are doing something wrong in the assignment. Maybe you are calling a function which requires a char[] in wich case you should use funct(letterGrade) without the [0]. If your problem persists you should post a bit more code. Update I fixed your code to make it compile. of course I don't know what it is supposed to be so I had to make some assumptions, but you should see how the syntax is supposed to be. public static void method() { double totalEarnedPoints = 1; double totalPossiblePoints = 1; double gradeScale[] = {1, 2, 3}; double gradeCutoffs[] = {1, 2, 3}; double gradePer = 0.0; char letter; double calcPercent = 1; gradePer = (totalEarnedPoints / totalPossiblePoints

Categories : Java

Convert char* to jstring in JNI, when char* is passed using va_arg
You could just check JNI api documentation. E.g. Here. You will find: jstring NewStringUTF(JNIEnv *env, const char *bytes); So all you have to do it something like this: char *buf = (char*)malloc(10); strcpy(buf, "1234567890"); jstring jstrBuf = (*env)->NewStringUTF(env, buf);

Categories : Java

adding char[] to char** (string to a list of strings)
You can't copy strings using =, you have to use a function - such as the standard strcpy function. So: configurations[*multiplicity][start] = "a,"; should be: strcpy(configurations[*multiplicity][start], "a,"); And the same type of patterns elsewhere.

Categories : C

Unexpected Error C2632: 'char' followed by 'char' is illegal
Those types have already been created via typedef (maybe) or #define (more likely) before your code tries to do it; taking a look at the preprocessor output (if that's possible with Visual-C++) may help you track down why that is.

Categories : Visual C++

C++ copying integer to char[] or unsigned char[] error
When you say i & 0xFF etc, you're creaing values in the range [0, 256). But (your) char has a range of [-128, +128), and so you cannot actually store those values sensibly (i.e. the behaviour is implementation defined and tedious to reason about). Use unsigned char for unsigned values. The clue is in the name.

Categories : C++

How to duplicate string token to char */char array
Call c_str on the string: word[i] = (const char *)strdup(t.c_str()); For reference: http://en.cppreference.com/w/cpp/string/basic_string/c_str

Categories : C++

How to initialize a char array using a char pointer in C
"How come this does not work?" Because that's not how the C language was defined. You can create a copy using strdup() [Note that strdup() is not ANSI C] Refs: C string handling strdup() - what does it do in C?

Categories : C

How to convert HTML char to UNICODE char
You're probably looking for WebUtility.HtmlDecode(). That should decode the values from the HTML entity (&#8220;) to a character. Note that it's WebUtility since I think you're trying to accomplish this on a desktop application. If not, use HttpUtility instead.

Categories : C#

Does a 2-char check digit for a barcode use the first or second char?
There are different weights for different barcode formats. You have described the format for the EAN format - a 1313 weighting. Whereas UPC uses a 3131 weighting scheme. ISBN-10 uses a completely different scheme - the weights are different and the calculation is done modulo 11. I think the reference you are using is assuming that the digits are indexed starting at 1 not 0. The effect is that you have mixed up odd and even characters. So the sum is 3 x 19 + 7 = 64 and therefore the check digit is 6 not 0. For EAN and UPC, the check digit is the value that must be added to the sum to get a number evenly divisible by 10. Update Your description of the check digit algorithm is accurate only for certain classes of EAN barcodes because the weights are aligned such that the last digit is alw

Categories : C#

Java char array seems to need more than 2 bytes per char
I guess what you are seeing can be easily explained by how the heap in the JVM is organized. When you pass the parameter -Xmx to the JVM, you are defining what the maximum heap size should be. However, it is not directly related to the maximum size of an array that you can allocate. In the JVM, the garbage collector is responsible for allocating memory for objects and for cleaning up dead objects. It is the garbage collector that decides how it organizes the heap. You usually have something called Eden space, then two survivor spaces and finally the tenured generation. All of these are inside the heap, and the GC divides the maximum heap among them. For more details on these memory pools, check this brilliant answer: http://stackoverflow.com/a/1262474/150339 I don't know what the defau

Categories : Java



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.