question
stringlengths
25
894
answer
stringlengths
4
863
I'm currently using C Builder: DWORD finalAddress = 0xFFFFFFFF; TListItem *ListIt; ListIt->Caption = finalAddress; This will output: 4294967295 (which is 0xFFFFFFFF in DEC) I want it to show 0xFFFFFFFF. How do I do that?
Assuming that you have access to C++ standard library, try this: ``` #include <sstream> #include <iostream> #include <string> std::ostringstream ss; ss << std::hex << finalAddress; AnsiString ansiHex = AnsiString (ss.str().c_str()); ListIt->Caption = ansiHex; ``` This last assignment may not work - I do not have a...
In CMake, is there a way to specify that all my executables links to some library? Basically I want all my executables link to tcmalloc and profiler. Simply specify -ltcmalloc and -lprofiler is not a good solution because I want to let CMake find the paths to the library in a portable way.
You can override the built-inadd_executablefunction with your own which always adds the required link dependencies: ``` macro (add_executable _name) # invoke built-in add_executable _add_executable(${ARGV}) if (TARGET ${_name}) target_link_libraries(${_name} tcmalloc profiler) endif() endmacro...
Just wondering if it's safe to cast like this: ``` char **cpp; // ... allocation and what not void *vp = (void *)cpp; // ... cpp = (char **)vp; ``` should a void ** be used or is void * fine? This works on a couple of my boxes without issue but was wondering if it could cause problems on certain systems.
The cast is always safe, dereferencing it is safe as long as the pointer is valid. The only case where you'd use avoid **is when you plan to dereference it to get avoid *. However, unless you do pointer arithmetics it won't really matter. As you can see onhttp://codepad.org/UcZUA0ULit works fine no matter if you usev...
Here's a sample program: ``` #include <stdio.h> void foo(int b[]){ printf("sizeof in foo: %i\n", sizeof b); } int main(){ int a[4]; printf("sizeof in main: %i\n", sizeof a); foo(a); } ``` The output is: ``` sizeof in main: 16 sizeof in foo: 8 ``` Question is, what's the point of that syntax if it...
It's syntactic sugar:void foo(int b[])suggests thatbis going to be used as an array (rather than a single out-parameter), even though it really is a pointer.It's a left-over fromearly versions of C, where postfix[]was the syntax for a pointer declaration.
I've been having some trouble moving a C project compiled and running in unix environment (through JNI) to Windows. While I have been able to compile the program in windows and add the path leading to it in my runtime environment I've been getting the error afterSystem.loadLibrary(): ``` classes\x32\coremod.dll: Can...
I didn't know this but you can use a program calledDEPENDS.exeto discover the dll's which are used by the target. In my case this highlighted the only dll not already registered, meaning I could simply add it to the%PATH%in order to get my program running.
This is kind of a very basic question. I just wanted to know what will be in the memory of a void type of pointer. Any help is really appriciated. Thanks!
Avoidpointer is just a value which provides an address in memory. What is actually pointed to by avoidpointer cannot be determined without further information. As to what is in the memory occupied by thevoidpointer, it will be a 32 bit value on a 32 bit architecture and 64 bit value on a 64-bit architecture (and so o...
I want to print the following details from a windows console application Total RAM Available, total RAM used, RAM used by the applicationTotal CPU used, CPU used by the applicationTotal hard disk memory available, used memory size I found lot of way to do this in online. Can any one tell me which is the best way to ...
Total RAM available -GetProcessMemoryInfoTotal CPU used -GetProcessTimesTotal hard disk memory available -GetDiskFreeSpace
I'm just trying to adjust contrast/ brightness in an image in gray scale to highlight whites in that image with Opencv in C. How can I do that? is there any function that makes this task in opencv? Original image: Modified image: Thanks in advance!
You could also check out the OpenCV CLAHE algorithm. Instead of equalizing the histogram globally, it splits up the image into tiles and equalizes those locally, then stitches them together. This can give a much better result. With your image in OpenCV 3.0.0: ``` import cv2 inp = cv2.imread('inp.jpg',0) clahe = cv2....
I did search but I did't find any BPF code to use on my computer, also there isn't any example code to use. My goal is to find low level functions to filter packets. I am working in C program language. I am using Ubuntu 12.04 with 3.2.0 kernel.
You may want to look into thepcaplibrary, from the folks who brought you tcpdump. Pcap is a cross-platform packet filtering library with support for BPF filters.
I need to panic kernel after some operations are done and verify what operation did Can some one help me to know if there is any way? I searched a lot but no luck I am looking for some generic call thanks in Advance!
You can try asysrq trigger: ``` echo c > /proc/sysrq-trigger ``` 'c' - Will perform a system crash by a NULL pointer dereference. A crashdump will be taken if configured.
I'm trying to figure out how to set up an event that could be carried into a child process. I need this in order to calculate the time it took for the parent process to communicate with the child process. The code I've got is here:http://pastebin.com/euVfSNegThe problem is that when the app2.exe calls app3.exe nothing...
TheMSDN pagesays: lpEventAttributesA pointer to aSECURITY_ATTRIBUTESstructure. If this parameter is NULL,the handle cannot be inherited by child processes.A child process created by the CreateProcess function can inherit a handle to an event objectif the lpEventAttributes parameter of CreateEvent enabled inhe...
Fromthe webI understand that C containsNULkeyword. But while compiling I get an error ``` NUL undeclared first use in this function' ``` My code fragment: ``` for (;;) { char ch = (*pzDest = *pzSrc); if (ch == NUL) break; if (ch == ':') { *pzDest = NUL; b...
There'sNULLand then there'sNUL. NULL is defined in stddef.h, is used very widely, and is a reference to a null pointer. NUL is different - it is the first character in the standard ASCII character set, and more importantly,it is not a standard macro. You may have to define it yourself. To define NUL, do: ``` #defi...
I want to implement a calendar app and wanted to handle recurring events, as calculation of recurrence is complex I was wondering if any open source libraries are available. I would prefer these libs to be in C/C++.I found some libs using ruby. But I am not sure how to use those in a C++ environment.
Yes, you can uselibicalwhich allows you to expand all recurrences in theiCalendarproposed standard. Beware: implementing aseriouscalendar app requires ahugeeffort. Unless you are forced to do this, think twice.
Let us say in some part of the code that a macro has been defined. During compilation, I want to learn if it has been defined and is being used. How might I do this?
Check with#ifndefdirective and throw an error with#errordirective : ``` #ifndef A_MUST_HAVE_MACRO #error "A must have macro not defined" #endif ```
``` #include <stdio.h> int main(){ char *c=""; printf("Input: "); scanf_s("%c", c); printf("%x", *c); } ``` I want to input a few characters, and then output the entire string as a hexadecimal value. How do I do this?
You need abuffer, not a string constant, to read into. Also, never use any of the*scanffunctions, and never use any of the*_sfunctions either. The correct way to write your program is something like this: ``` int main(void) { char line[80]; char *p; fputs("Input: ", stdout); fgets(line, sizeof line, stdin)...
assume i have a macro like this#define MY_MACRO(n) xxxxxxxxx // some code then I want to use it many times like ``` MY_MACRO(0) MY_MACRO(1) MY_MACRO(2) MY_MACRO(3) ... MY_MACRO(100) ``` is there a better way of doing this? (I have to use macros)
You can use iteration. You can use boost's preprocessor library or write your own. Good luck on the latter...it's frickin complicated. Preprocessor metaprogramming is tricky business. Using boost preprocessor you would do something like so: ``` #define MY_MACRO_N(Z,N,D) MY_MACRO(N) BOOST_PP_REPEAT(101, MY_MACRO_...
I am trying to write a code that can get the names of the installed drivers in my Windows computer in C (via winapi)? I am really new to C and I do not know what I can do ? Can you please help me with this situation ? Thank you very much
You need the setup API. Start with this article:How to enumerate hardware devices by using SetupDi calls
gcc, Ubuntu. Have done: sudo apt-get install libssl-dev Build with -lssl, but during linkage get error: undefined reference to `DES_set_odd_parity' ? EDITED: g++ linear_des.cpp -lssl
DES_set_odd_parityis part oflibcryptoso you should try linking that as well. Something on these lines:g++ linear_des.cpp -lssl -lcryptoHope this helps!PS: It might be a good idea to make use ofpkg-configtool & compile something on these lines:g++ linear_des.cpp $(pkg-config --cflags --libs openssl)
Here is what I have (message() is a specialized logging function from a third party library): ``` #define LOG(fmt, ...) message("%s %s(): #fmt", __FILE__, __func__, __VA_ARGS__); ``` So I want to be able to do things like: ``` LOG("Hello world") LOG("Count = %d", count) ``` And have it expand to: ``` message("%s ...
Don't put#fmtin the quotes. Just usestring literal concatenationto join the two literals. ``` #define LOG(fmt, ...) message("%s %s(): " fmt, __FILE__, __func__, __VA_ARGS__); ```
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened,visit the help center.Closed11 years ago. Hello Friend,I am novice in Python....
in c ``` int first_array[] = { 3,4,5}; if ( (first_array != null) && (first_array[0] == 3 )) { printf("5"); } ```
I have the following code. ``` #include<stdio.h> #include<string.h> int main() { char str1[1000]="/"; char unit[1000]="Hai"; strcat(str1,unit); printf("\nvalue of unit: %s\n", unit); return 0; } ``` strcatshould append"/"to"Hai". So the expected output ofprintfis 'value of unit: Hai/', but I get...
Just read the docs ofstrcat(): it will tell you that it is called withstrcat(dest, src). So in your case,str1will contain"/Hai". If you wantunitto be"Hai/", you should callstrcat(unit, str1).
As per my understanding there are two RSA signature schemes - PSS (Probabilistic Signature Scheme) and the old PKCS1-v1_5: Can I use RSA_verify() API to check RSA signature under both schemes ?
If you have a recent version - see:http://fixunix.com/openssl/526614-signing-verifying-messages-rsassa-pss.htmlfor how to use it.
I need to write code in C that will indicate and notify me when the laptop battery power is low. I know that I can use the following: ``` BOOL WINAPI GetSystemPowerStatus( __out LPSYSTEM_POWER_STATUS lpSystemPowerStatus ); ``` But I want to send a function to the operating system that will notify me when p...
I have never used these APIs, but what you are looking for seems to beWM_POWERBROADCAST. There are various values forwParamthat you could check upon receiving that message, such asPBT_APMBATTERYLOW. When you receive aWM_POWERBROADCASTmessage with the appropriatewParamvalue, callGetSystemPowerStatus()from there.
I have a customer supplied RSA signature verification API description that takes the parameters - Modulus(N), E, Padding scheme, salt, , message and its signature. I have to implement the signature verification API (I can leverage openssl APIs). With the above information, can I verify signature passed ? Or I need ad...
The public key for RSAisN and E as a pair. The private key comprises p, q and d - although d can be derived knowing p, q and e. So, in short terms: you should be able to, yes. The additional parameters (salt, padding scheme) are so that you correctly utilise RSA in terms of PKCS #1, and correctly decode RSA signatur...
I get an EXC_BAD_ACCESS error in the last statement when calling the following simplified function: ``` void test(char *param, ...) { va_list vl; va_start(vl, param); double a = va_arg(vl, double); double b = va_arg(vl, double); double *result = va_arg(vl, double*); *result = a*b; va_end(vl); } ``` The...
I think the problem is in you sending adoubleas3instead of3.0. A normal3will be treated as integer but in thetestfunction you are retrieving doubles which are bigger than aninton most platforms and you might end up reading wrong locations which inturn leads toEXC_BAD_ACCESSrun time signal being generated
There are these questions which I am not able to get answers for. Any help is very useful. How does linking actually happen in the C compilation model?If I am using Linux and GCC, how doesglibclink to the main program. Is it static or dynamic linking?
For your first question a simple one para answer is not sufficient. Read the following resourcesArticle on linking at cprogramming.comWikipedia articleman page ofldSO Postglibcis linkeddynamicallyunless you specify-staticoption to the linker. Undernormalcircumstances, linking a huge lib likeglibcstatically doesn't hel...
I've got some code which reads lines from a txt file and then does adds to a database. If you type data straight into the txt file, then this is sufficient to recognise a newline:if (ch == '\n') However, if you cut & paste out of Microsoft Word, checking for\ndoesn't work. If I dump out the hex values / characters ...
Windows uses a pair of characters to end a line: a carriage return (0x0d) followed by a line feed (0x0a). You can write these in C as'\r'and'\n', respectively.
How to connect Oracle usingOCILIBwith hostname and port number configured. It by default takes localhost as hostname. I also checked in theOCI_ConnectionCreatefunction, but it doesn't asks for hostname and port number: ``` cn = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT); ``` As my requirement is...
question answered in the original topic on OCILIB forum on SF.NETLink to topic
I'm looking for how to get the name of the terminal emulator (« aterm », « xterm », « konsole », etc.) with C Programming langage (GNU/Linux). I have done several researches, but I didn't find anything.
I doubt there's a reliable way to check this. As @larsmans suggested, you can check theTERMenv variable, but most emulators use the same terminal setting.. I would check the parent process id (getppid) and its parent (linux: programmatically get parent pid of another process?) and so on till you find a process with ...
I write a module,and want add it to kernel.It will print a world when i insmod the module.but it will not... the module as: ``` #include <linux/module.h> #include <linux/init.h> static int __init hello_init() { printk(KERN_EMERG"Hello World!\n"); return 0; } static void __exit hello_exit() { printk("<6...
Since you didn't get a compile/linking error andinsmod/modprobedidn't complain about missing symbols, there are two reasons why this can happen: Someone defined a macroprintk()You looked in the wrong place. The text will be printed to the syslog. To see that, usedmesg | tail
I came across this code construct in Linux and would like to understand it ``` struct mystruct { int x; int b[40]; }; /*later */ static struct mystruct e = { .x = 5, .b = {-1}, }; ``` What does .b = {-1} do ? Does it initialize only the first or all ...
``` static struct mystruct e = { .x = 5, .b = {-1}, }; ``` here it initializes b[0] to -1. other elements are initialized to 0.
I need to find out the available (installed in the system) GCC version (Major and minor) inside the execution of a c program (in runtime). Meaning, programatically extract the version of the available gcc (same as if I was in a shell and typed gcc --version, but in a c program). The__GNUC__and__GNUC_MINOR__are only u...
There is a simple way: ``` $ gcc -dumpversion 4.6 ```
Consider the following program. ``` #include <stdio.h> int main() { int a[10]={0}; printf("%p %p\n", a, &a); printf("%d %d\n", *a, *(&a)); return 0; } ``` a and &a are same. But *a and *(&a) are not. I am out of answers. Please help.
a[i]is the same as*(a + i). So the first element is at the same address as the array itself. You'll find a more detailed explanation in another question here on SO:How come an array's address is equal to its value in C?
for my word game i'm comparing chars in words, 6 in the first word, 6 in the random word. Now I want it to do things when certain letters are on there place. for example if ``` (aChar1 == aChar7 && aChar2 == aChar8){ //do something } ``` but later in my code there is ``` (aChar1 == aChar7 && aChar2 == aChar8 && a...
use this and tell me if it works achar3!=achar9
i want to create queue with dynamic array, the problem is when i test the q.rear value in int main() (for inserting data later) it's not -1 anymore. Which part did i do wrong? here's a piece of the code: ``` #include <stdio.h> #include <conio2.h> #include <stdlib.h> typedef struct{ int *data; int front,rear...
You didn't assign the result ofcreate()toq. The following callscreate()and discards the result, leavingqin its original state: ``` create(size); ``` To fix, replace the above line with: ``` q = create(size); ```
I want to sent TCP packets via raw socket and then I got stuck with the checksum field of tcp header. since I dont know how to figure out the actual IP address that raw socket had used, it seems impossible to construct TCP pseudo-header for checksum computation.
You know the ip address. Because: Prior to sending any data over this socket you ought tobind()it, for doing so you need to specify the ip address you are looking for. Update: Binding toINADDR_ANYbinds to any local interface. To get information on all local interfaces (including each's ip address) you might usege...
I am writing a piece of code that needs to copy values from one char pointer to another. The primary requirements are that the code should work as fast as possible and across as many platforms as possible. I see that I can do this string copy using either of these two functions: ``` char * strncpy ( char * destinati...
They don't do the same thing. If you're certain the source and destination buffers are the same size, go withmemcpy. If not,strncpydoes bound checking and it's the way to go. But unless you do millions of operations, this shouldn't be a factor in your decision. Do some profiling first, see how much time (if any) you ...
I'm somewhat confused by#definestatements. In libraries, they seem to be a means of communication across different files, with lots of#ifdefs and#ifndefs. Having said that, I now have two filesfile1.candfile2.ccompiled together, with#define TEST 10insidefile2.c. Yet, when I useTESTinsidefile2.cthe compiler gives the ...
#defines are not global, they are just a substitution where ever they are used (if declared in the same compile unit) They arenotglobals, they arenotsymbols, they areirrelevantat linkage, they are only relevant atpre-compilation.
Why I am getting this output ? Byte x ; x = 127; x<<=3;//same as x = x <<3 println(x) output : -8 When i note down it in paper and twiddled the bits I was getting -11111000 and that is = 248? I suppose Byte occupies 1 byte (8 bits) .Dont know whether it is signed or unsigned?I assuem it to be signed? because the ...
It's becausebyteis a signed data type which usestwo's complement. And248-256is equal to-8.
I always locate element by getElementId, and sent value by using document.getElementId(id).value = "something". but I found an button without Id or Name < input type="submit" class="button" accesskey="l" value="click me" tabindex="3"> now how can I locate it ???
I think you need: ``` IWebElement element = webDriver.FindElement(By.ClassName("button")); ``` Though I don't understand what you are currently using from selenium?
Make's implicit rules are supposedly there to make writing Makefiles easier but, if my understanding is correct, if my C files depend on any header files, I need to write the rule, explicitly. Am I right? This seems to serioiusly lower the usefulness of implicit rules, since most C files depend on a couple of header f...
You can autogenerate header dependencies with gcc using the following makefile snippet ``` SOURCES := $(wildcard *.c) DEPS := $(SOURCES:%.c=%.d) CFLAGS += -MMD -include $(DEPS) ``` The code might need some adjustments to work with your particular ruleset.
I am trying to implement double-buffering in a Win32 application, so I need the controls of a window to be painted from the backmost-control to the frontmost. As I understand it,WM_EX_COMPOSITEDdoes this, but it also does double-buffering itself1. How can I get windows to be painted from bottom to top likeWS_EX_COMPOS...
Use theWS_EX_TRANSPARENTextended window style to make the top-level window paint last.
I'm looking for how to get the name of the terminal emulator (« aterm », « xterm », « konsole », etc.) with C Programming langage (GNU/Linux). I have done several researches, but I didn't find anything.
I doubt there's a reliable way to check this. As @larsmans suggested, you can check theTERMenv variable, but most emulators use the same terminal setting.. I would check the parent process id (getppid) and its parent (linux: programmatically get parent pid of another process?) and so on till you find a process with ...
I write a module,and want add it to kernel.It will print a world when i insmod the module.but it will not... the module as: ``` #include <linux/module.h> #include <linux/init.h> static int __init hello_init() { printk(KERN_EMERG"Hello World!\n"); return 0; } static void __exit hello_exit() { printk("<6...
Since you didn't get a compile/linking error andinsmod/modprobedidn't complain about missing symbols, there are two reasons why this can happen: Someone defined a macroprintk()You looked in the wrong place. The text will be printed to the syslog. To see that, usedmesg | tail
I came across this code construct in Linux and would like to understand it ``` struct mystruct { int x; int b[40]; }; /*later */ static struct mystruct e = { .x = 5, .b = {-1}, }; ``` What does .b = {-1} do ? Does it initialize only the first or all ...
``` static struct mystruct e = { .x = 5, .b = {-1}, }; ``` here it initializes b[0] to -1. other elements are initialized to 0.
I need to find out the available (installed in the system) GCC version (Major and minor) inside the execution of a c program (in runtime). Meaning, programatically extract the version of the available gcc (same as if I was in a shell and typed gcc --version, but in a c program). The__GNUC__and__GNUC_MINOR__are only u...
There is a simple way: ``` $ gcc -dumpversion 4.6 ```
Consider the following program. ``` #include <stdio.h> int main() { int a[10]={0}; printf("%p %p\n", a, &a); printf("%d %d\n", *a, *(&a)); return 0; } ``` a and &a are same. But *a and *(&a) are not. I am out of answers. Please help.
a[i]is the same as*(a + i). So the first element is at the same address as the array itself. You'll find a more detailed explanation in another question here on SO:How come an array's address is equal to its value in C?
for my word game i'm comparing chars in words, 6 in the first word, 6 in the random word. Now I want it to do things when certain letters are on there place. for example if ``` (aChar1 == aChar7 && aChar2 == aChar8){ //do something } ``` but later in my code there is ``` (aChar1 == aChar7 && aChar2 == aChar8 && a...
use this and tell me if it works achar3!=achar9
i want to create queue with dynamic array, the problem is when i test the q.rear value in int main() (for inserting data later) it's not -1 anymore. Which part did i do wrong? here's a piece of the code: ``` #include <stdio.h> #include <conio2.h> #include <stdlib.h> typedef struct{ int *data; int front,rear...
You didn't assign the result ofcreate()toq. The following callscreate()and discards the result, leavingqin its original state: ``` create(size); ``` To fix, replace the above line with: ``` q = create(size); ```
I want to sent TCP packets via raw socket and then I got stuck with the checksum field of tcp header. since I dont know how to figure out the actual IP address that raw socket had used, it seems impossible to construct TCP pseudo-header for checksum computation.
You know the ip address. Because: Prior to sending any data over this socket you ought tobind()it, for doing so you need to specify the ip address you are looking for. Update: Binding toINADDR_ANYbinds to any local interface. To get information on all local interfaces (including each's ip address) you might usege...
I am writing a piece of code that needs to copy values from one char pointer to another. The primary requirements are that the code should work as fast as possible and across as many platforms as possible. I see that I can do this string copy using either of these two functions: ``` char * strncpy ( char * destinati...
They don't do the same thing. If you're certain the source and destination buffers are the same size, go withmemcpy. If not,strncpydoes bound checking and it's the way to go. But unless you do millions of operations, this shouldn't be a factor in your decision. Do some profiling first, see how much time (if any) you ...
I'm somewhat confused by#definestatements. In libraries, they seem to be a means of communication across different files, with lots of#ifdefs and#ifndefs. Having said that, I now have two filesfile1.candfile2.ccompiled together, with#define TEST 10insidefile2.c. Yet, when I useTESTinsidefile2.cthe compiler gives the ...
#defines are not global, they are just a substitution where ever they are used (if declared in the same compile unit) They arenotglobals, they arenotsymbols, they areirrelevantat linkage, they are only relevant atpre-compilation.
Why I am getting this output ? Byte x ; x = 127; x<<=3;//same as x = x <<3 println(x) output : -8 When i note down it in paper and twiddled the bits I was getting -11111000 and that is = 248? I suppose Byte occupies 1 byte (8 bits) .Dont know whether it is signed or unsigned?I assuem it to be signed? because the ...
It's becausebyteis a signed data type which usestwo's complement. And248-256is equal to-8.
Consider the following program. ``` #include <stdio.h> int main() { int a[10]={0}; printf("%p %p\n", a, &a); printf("%d %d\n", *a, *(&a)); return 0; } ``` a and &a are same. But *a and *(&a) are not. I am out of answers. Please help.
a[i]is the same as*(a + i). So the first element is at the same address as the array itself. You'll find a more detailed explanation in another question here on SO:How come an array's address is equal to its value in C?
for my word game i'm comparing chars in words, 6 in the first word, 6 in the random word. Now I want it to do things when certain letters are on there place. for example if ``` (aChar1 == aChar7 && aChar2 == aChar8){ //do something } ``` but later in my code there is ``` (aChar1 == aChar7 && aChar2 == aChar8 && a...
use this and tell me if it works achar3!=achar9
i want to create queue with dynamic array, the problem is when i test the q.rear value in int main() (for inserting data later) it's not -1 anymore. Which part did i do wrong? here's a piece of the code: ``` #include <stdio.h> #include <conio2.h> #include <stdlib.h> typedef struct{ int *data; int front,rear...
You didn't assign the result ofcreate()toq. The following callscreate()and discards the result, leavingqin its original state: ``` create(size); ``` To fix, replace the above line with: ``` q = create(size); ```
I want to sent TCP packets via raw socket and then I got stuck with the checksum field of tcp header. since I dont know how to figure out the actual IP address that raw socket had used, it seems impossible to construct TCP pseudo-header for checksum computation.
You know the ip address. Because: Prior to sending any data over this socket you ought tobind()it, for doing so you need to specify the ip address you are looking for. Update: Binding toINADDR_ANYbinds to any local interface. To get information on all local interfaces (including each's ip address) you might usege...
I am writing a piece of code that needs to copy values from one char pointer to another. The primary requirements are that the code should work as fast as possible and across as many platforms as possible. I see that I can do this string copy using either of these two functions: ``` char * strncpy ( char * destinati...
They don't do the same thing. If you're certain the source and destination buffers are the same size, go withmemcpy. If not,strncpydoes bound checking and it's the way to go. But unless you do millions of operations, this shouldn't be a factor in your decision. Do some profiling first, see how much time (if any) you ...
I'm somewhat confused by#definestatements. In libraries, they seem to be a means of communication across different files, with lots of#ifdefs and#ifndefs. Having said that, I now have two filesfile1.candfile2.ccompiled together, with#define TEST 10insidefile2.c. Yet, when I useTESTinsidefile2.cthe compiler gives the ...
#defines are not global, they are just a substitution where ever they are used (if declared in the same compile unit) They arenotglobals, they arenotsymbols, they areirrelevantat linkage, they are only relevant atpre-compilation.
Why I am getting this output ? Byte x ; x = 127; x<<=3;//same as x = x <<3 println(x) output : -8 When i note down it in paper and twiddled the bits I was getting -11111000 and that is = 248? I suppose Byte occupies 1 byte (8 bits) .Dont know whether it is signed or unsigned?I assuem it to be signed? because the ...
It's becausebyteis a signed data type which usestwo's complement. And248-256is equal to-8.
I always locate element by getElementId, and sent value by using document.getElementId(id).value = "something". but I found an button without Id or Name < input type="submit" class="button" accesskey="l" value="click me" tabindex="3"> now how can I locate it ???
I think you need: ``` IWebElement element = webDriver.FindElement(By.ClassName("button")); ``` Though I don't understand what you are currently using from selenium?
i am using msecs_to_jiffies(msecs) to get delay. I need a delay of 16 ms. But the problem is the function return 1 for input 1-10, 2 for 11-20, 3 for 21-30 and son on. Hence i am unable to set proper delay. I can set delay only in factors of 10 ms. I can't change the HZ value and the function cant sleep also. Kindly ...
It seems your system HZ value is set to 100. If you wish to suspend execution for a period of time in a resolution lower then the system HZ, you need to use high resolution timers (which use nsec resolution, not jiffies) supported in your board and enabled in the kernel. See here for the interface of how to use them:...
if for instance i have a string:Hi:my:name:is:lacrosse1991:how could I usestrtokto retrieve just theis(in other words the fourth field)? This would be similar to how you would use cut in bash, where i would just docut -d ":" -f 4. If this is the wrong function to be doing such a thing, please let me know, any help is ...
If you know it's the 4th field you just call strtok() 4 times - there is no way of jumping to the 4th field without scanning the entire string ( which is what strtok is doing)
``` #include <stdio.h> #include <stdlib.h> int main(int argc,char *argv[]) { system("PAUSE"); return 0; } ``` After i Compiled the programme, i click run. it still tips me " project is not compiled" why? i am sorry, i am a new learner of c. i am usingdev c++, on xp,ctrl+F9compile thenctrl+F10run it showspr...
``` multiple definition of main ``` Maybe in your project there is 2 Main function.. You should at least delete/change one.. if I see, there is 1-3.c and 1c.c and the compile is error.. ``` [Build Error] ``` CMIIW
I want to choose randomly from among 4 directions: ``` movePlayer(map, &positionPlayer, direction); ``` where direction is one ofUP,DOWN,LEFT, andRIGHT. I haven't yet found out how to do this with therand()function. How can I do this? Do I need to assign a number to each direction and then choose a random number w...
Yes, you need assign a number to each direction. ie. 0=UP 1=DOWN 2=LEFT 3=RIGHT You need code like this: ``` int direction = rand()%4; ```
I get the id of my hard disk like this: ``` system("hdparm -i /dev/xxx > /tmp/hdid"); ``` How can I get the device name (/dev/sdaor/dev/sdbor/dev/hda, etc) from a program in C? Thanks
Your question is not clear at all to me - If this is Linux then try: getmntent() to enumerate mounted file systems The /proc/mounts directory lists mounted devices The /dev/disks directory lists disk devices, their names are usually sda, sdb, etc. This includes devices that are not mounted. The entries there are ...
I am a student and I'm taking a course where my project is to write a server using unix sockets, threads or epoll, and so forth. However, as the client takes his input from the user, I wanted to go an extra mile and give it some sort of memory for the commands he has given in the past; like the shell or gdb has. I h...
TheGNU readline libraryprovides this functionality.
I have downloaded rx. Can somebody please tell of a suitable ide for debugging and building the source code of "rdf-3x". As per the operating system: ubuntu & Windows are both fine for me. I tried netbeans (C++) but it does not work for me, since it does not treat all the folders within as one project, rather it trea...
I'm using Eclipse.. It's user friendly for me..You can try it.http://www.eclipse.org/cdt/ CMIIW
Not sure what the problem is here, but I keep getting the result of 0. The expected result is 0.2222222. I figure I must be assigning a zero to one of my variables but I can't figure out where this is happening. Any help would be appreciated. Thanks ``` #include <stdio.h> #include <math.h> int main() { double vs...
You need to initializecountbefore using it:int count = 0;
When I initialize this array inside my struct. I get the error message - syntax error : '{'. Unexpected token(s) preceding '{'; skipping apparent function body. ``` int array[8][2] = {{3,6},{3,10},{3,14},{8,4}, {8,8},{8,12},{8,16},{12,2}}; ``` I'm not sure what is wrong as I copied the syntax from my textb...
You cannot initialize a variable inside a struct declaration, doesn't matter if an array or int. Yet, you can initialize the array in the struct initialization. ``` struct foo { int x; int array[8][2]; }; struct foo foovar = {1, {{3,6},{3,10},{3,14},{8,4}, {8,8},{8,12},{8,16},{12,2}}}; ```
I have account numbers that are in the same form as SS numbers, for example, 123-12-1234 What C variable type should be sued to store these? Can a primitive type hold such 'numbers'? A brief explanation would be great too! Thanks
What do you want to do with these numbers? You may want to store them as a string if you want to display them. You may want to store it as 3 ints if each section means something and you will be comparing them. You may want to store it as 1 int and handle formatting when you display it if you will be doing a lot of com...
This is follow-up to:using xslt to create an xml file in c ``` <element1 type="type1" name="value1"> <start play="no"/> <element2 aaa="AAA"/> <element2 bbb="BBB"/> <element3 ccc="CCC"> <element4/><!-- play="no"/>--> </element3> </element1> ``` Lets say I get this xml file, how do I read individual nod...
A schema is never a bad idea, however it won't help you read the xml as such. All schema would do given you validate the xml against it is tell you it follows whatever rules are in there. For the rest of it, a quick search on here would have found this.How can libxml2 be used to parse data from XML?
Can I assign a pointer to an integer variable? Like the following. ``` int *pointer; int array1[25]; int addressOfArray; pointer = &array1[0]; addressOfArray = pointer; ``` Is it possible to do like this?
Not without an explicit cast, i.e. ``` addressOfArray = (int) pointer; ``` There's also this caveat: 6.3.2.3 Pointers...6 Any pointer type may be converted to an integer type. Except as previously specified, the result is implementation-defined. If the result cannot be represented in the integer type, the behavior ...
Is it possible to create a single dll using 2 projects in MS VS 2008? Please let me know. I am using C and C++ as my programming language. Please provide me with an example. Thanks.
It's definitely possible to do this. The simplest way to structure the project is that Project1: Produces a .lib fileProject2: Produces a .dll which links the .lib from Project1 It's not really possible though to have two projects directly compile into a single DLL without an intermediate step of a .lib file. It c...
If we check the officialdocumentationwe can find various ways of interfacing Erlang and C/C++. A similar question was asked here in2009and I would like to know how the things changed since then. Is there any mature stable library that does all the dirty work of implementing binary protocols between Erlang and C? Is i...
Nothing have changed significantly since 2009, the top answer from the question you linked is still correct. NIFs became less experimental starting from R14 and are actively used in some projects, but they are still incompatible with HiPE compiler (native flag to compile).
If I want to get the name by id vertex i can use this funcion:VAS(g, "name",id)but if I want the opposite way,to get the id by the name, how can I do that?
igraph doesn't provide, on its own, a means to look up vertices by name, and for good reason - mapping from name to ID is a more challenging problem than mapping from ID to name, which is a simple array lookup operation. You could iterate through all the vertices and stop at the one that matches, but this is ineffici...
Can any one tell me how to typecast achar*pointer toint*in OpenCL kernel function?? I tried((int*) char_pointer)but it is not working.
You have to qualify the pointer with the correct address space, I think. If you don't specify the address space,__privateis assumed, but your source pointer seems to be a__globalpointer (from your comment), so the address spaces are incompatible. So try to use(__global int*)instead of just(int*).
is there an open implementation for an aztec 2D barcode (for the Deutsche Bundesbahn) generator. I do not need the "aztec-data to bitmap", but i need the "input-data to aztec-data" part, the drawing itself is no problem with drawing primitives.
ZXingalso supports Aztec encoding since version 2.2.
``` void* heap = malloc(100); char *c = heap; strcpy(c, "Terence"); printf("heap = %s\n", heap); free(heap); heap = malloc(100); printf("heap = %s\n", heap); ``` the output is: ``` heap = Terence heap = ``` That is what I expect, but now I have a far more complex code, the structure is similar to the above, but the...
The region of memory allocated bymallochas an indeterminate initial value. From the C Standard (emphasis mine): (c99, 7.20.3.3p2) "The malloc function allocates space for an object whose size is specified by size andwhose value is indeterminate*." Usecallocormemsetaftermallocto have a determinate value.
This question already has answers here:Closed11 years ago. Possible Duplicate:concatenate char array in C How to concatenate: ``` char *a="abcd"; char *b="1234"; ``` using the strcat()? And answer to the same when user enters *a and *b? EDITmissed out this: without using another array.
You can't monkey around with the string literals you've already initialized - they're sitting somewhere in memory & can't/shouldn't be rewritten. If you don't want another statically-defined array but don't mind dynamic allocation, the code below may accomplish what you're looking for: ``` char *a = "abcd"; char *b ...
In the below program, as far as in my knowledge once we allocate some memory then if we are chaging the address fromptr to ptr++, then when we are callingfreewithptri.efree(ptr). Then the program should crash. But in this program works fine. How it works? I am using Code::Bocks in Windows XP. Please help me. ``` int...
The behavior of this program isundefinedfrom the very moment that you store a value through anint*pointing to a single byte. There's no guarantee of a crash. Specifically, it seems like yourfreedoesn't (maybe can't) check its argument properly. Try running this program with amallocdebugging library.
I have a child process specified bypid. This process could be: RunningDefunct/Zombie (unreaped)Already reaped (and thus no longer exists) I would like to kill this process and ensure no zombie remains. Currently my code is ``` kill(pid, SIGKILL); int temp; waitpid(pid, &temp, 0); ``` Would this work? EDIT: The pr...
This looks fine so far, but I wonder why you would let case 3 happen. You should perform some bookkeeping, which of your child processes have terminated and are waiting to be reaped. One way would be to install a handler forSIGCHLD, setting a flag that awaitpidis in order. That way you guarantee that all pids are actu...
This is so stupidly simple but I'm just having issues with it. A text file has a header, e.g., ``` # Avizo BINARY-LITTLE-ENDIAN 2.1 define Lattice 496 384 470 Parameters { AlignTransform { slice0000 0 -0 -30 -1, slice0001 0 -0 -30 -1, slice0002 0 -0 -30 -1, ``` And I'm trying to read ...
I recommend that you usefgets, but if you insist on usingfscanf: ``` fscanf(fd, "%[^\n]\n", buff); ``` This will read a full line.
I've seen a bunch of functions in Linux code named __foo. What does the double underscore stand for and when should it be used?
It means it's a reserved identifer. Both C++ 03 and C99 standard mentioned about this. C99: 7.1.3 Reserved identifiersAll identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use.All identifiers that begin with an underscore are always reserved fo...
How can I set a pointer to a C array in my constructor? ``` @implementation NSBufferedInputStream { char *buffer; int bufferSize; } - (id)initWithFileAtPath:(NSString *)path { self = [super initWithFileAtPath:path]; if (self) { bufferSize = 100; buffer = char[bufferSize]; // ERROR: Ex...
If you truly need a dynamically-sized array, ``` - (id)initWithFileAtPath:(NSString *)path { self = [super initWithFileAtPath:path]; if (self) { bufferSize = 100; buffer = malloc(sizeof(char) * bufferSize); } } - (void)dealloc { free(buffer); [super dealloc]; } ``` Otherwise, if ...
I have this very simple code: ``` #include <stdio.h> #include <stdlib.h> int maxArr(int *arr) { int i=0; for (i = 0; i < 10; ++i) { printf("%d\n",arr[i]); } return 0; } int main() { int* i = {0,1,2,3,4,5,6,7,8,9}; maxArr(&i); return 0; } ``` but instead of printing 0,1,2,3...
Change your initialization ofito: ``` int i[10] = {0,1,2,3,4,5,6,7,8,9}; ``` ...and callmaxArraywith justi; i.e.maxArray(i).
This question already has answers here:How would I load a PNG image using Win32/GDI (no GDI+ if possible)?(5 answers)Closed9 years ago. Very simple question: how do I render a png image with GDI in C (including its transparencies)?
I went with GDI+ instead of GDI.
How do I compile 16-bit C code with GCC? I am trying to write a flat bootloader that just writes "Hello World!" to the computer and halts. ``` int main(int argc, char** argv) { char* value = "Hello World!"; __asm { mov si, value loop: lodsb cmp al, 0 halt: je halt ...
You don't. You can't. GCC doesn't generate 16-bit x86 code. Use Open Watcom C/C++ or the ancient Turbo C++ (v 1.01 is freely available online).
I have the following code to change the style of my window at runtime: ``` SetWindowLong(hwnd, GWL_EXSTYLE, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE); ``` The only problem is, it does not have the desired effect until I start dragging the window's edge to resize it. Is there something I need to do to get this working? I ...
You need to use SetWindowPos with the SWP_FRAMECHANGED flag for the update to take affect. If you don't need the size or position changed OR SWP_NOMOVE and SWP_NOSIZE to SWP_FRAMECHANGED
If I want to get the name by id vertex i can use this funcion:VAS(g, "name",id)but if I want the opposite way,to get the id by the name, how can I do that?
igraph doesn't provide, on its own, a means to look up vertices by name, and for good reason - mapping from name to ID is a more challenging problem than mapping from ID to name, which is a simple array lookup operation. You could iterate through all the vertices and stop at the one that matches, but this is ineffici...
Can any one tell me how to typecast achar*pointer toint*in OpenCL kernel function?? I tried((int*) char_pointer)but it is not working.
You have to qualify the pointer with the correct address space, I think. If you don't specify the address space,__privateis assumed, but your source pointer seems to be a__globalpointer (from your comment), so the address spaces are incompatible. So try to use(__global int*)instead of just(int*).
is there an open implementation for an aztec 2D barcode (for the Deutsche Bundesbahn) generator. I do not need the "aztec-data to bitmap", but i need the "input-data to aztec-data" part, the drawing itself is no problem with drawing primitives.
ZXingalso supports Aztec encoding since version 2.2.
``` void* heap = malloc(100); char *c = heap; strcpy(c, "Terence"); printf("heap = %s\n", heap); free(heap); heap = malloc(100); printf("heap = %s\n", heap); ``` the output is: ``` heap = Terence heap = ``` That is what I expect, but now I have a far more complex code, the structure is similar to the above, but the...
The region of memory allocated bymallochas an indeterminate initial value. From the C Standard (emphasis mine): (c99, 7.20.3.3p2) "The malloc function allocates space for an object whose size is specified by size andwhose value is indeterminate*." Usecallocormemsetaftermallocto have a determinate value.
This question already has answers here:Closed11 years ago. Possible Duplicate:concatenate char array in C How to concatenate: ``` char *a="abcd"; char *b="1234"; ``` using the strcat()? And answer to the same when user enters *a and *b? EDITmissed out this: without using another array.
You can't monkey around with the string literals you've already initialized - they're sitting somewhere in memory & can't/shouldn't be rewritten. If you don't want another statically-defined array but don't mind dynamic allocation, the code below may accomplish what you're looking for: ``` char *a = "abcd"; char *b ...
In the below program, as far as in my knowledge once we allocate some memory then if we are chaging the address fromptr to ptr++, then when we are callingfreewithptri.efree(ptr). Then the program should crash. But in this program works fine. How it works? I am using Code::Bocks in Windows XP. Please help me. ``` int...
The behavior of this program isundefinedfrom the very moment that you store a value through anint*pointing to a single byte. There's no guarantee of a crash. Specifically, it seems like yourfreedoesn't (maybe can't) check its argument properly. Try running this program with amallocdebugging library.
I have a child process specified bypid. This process could be: RunningDefunct/Zombie (unreaped)Already reaped (and thus no longer exists) I would like to kill this process and ensure no zombie remains. Currently my code is ``` kill(pid, SIGKILL); int temp; waitpid(pid, &temp, 0); ``` Would this work? EDIT: The pr...
This looks fine so far, but I wonder why you would let case 3 happen. You should perform some bookkeeping, which of your child processes have terminated and are waiting to be reaped. One way would be to install a handler forSIGCHLD, setting a flag that awaitpidis in order. That way you guarantee that all pids are actu...
This is so stupidly simple but I'm just having issues with it. A text file has a header, e.g., ``` # Avizo BINARY-LITTLE-ENDIAN 2.1 define Lattice 496 384 470 Parameters { AlignTransform { slice0000 0 -0 -30 -1, slice0001 0 -0 -30 -1, slice0002 0 -0 -30 -1, ``` And I'm trying to read ...
I recommend that you usefgets, but if you insist on usingfscanf: ``` fscanf(fd, "%[^\n]\n", buff); ``` This will read a full line.
I've seen a bunch of functions in Linux code named __foo. What does the double underscore stand for and when should it be used?
It means it's a reserved identifer. Both C++ 03 and C99 standard mentioned about this. C99: 7.1.3 Reserved identifiersAll identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use.All identifiers that begin with an underscore are always reserved fo...
How can I set a pointer to a C array in my constructor? ``` @implementation NSBufferedInputStream { char *buffer; int bufferSize; } - (id)initWithFileAtPath:(NSString *)path { self = [super initWithFileAtPath:path]; if (self) { bufferSize = 100; buffer = char[bufferSize]; // ERROR: Ex...
If you truly need a dynamically-sized array, ``` - (id)initWithFileAtPath:(NSString *)path { self = [super initWithFileAtPath:path]; if (self) { bufferSize = 100; buffer = malloc(sizeof(char) * bufferSize); } } - (void)dealloc { free(buffer); [super dealloc]; } ``` Otherwise, if ...
I have this very simple code: ``` #include <stdio.h> #include <stdlib.h> int maxArr(int *arr) { int i=0; for (i = 0; i < 10; ++i) { printf("%d\n",arr[i]); } return 0; } int main() { int* i = {0,1,2,3,4,5,6,7,8,9}; maxArr(&i); return 0; } ``` but instead of printing 0,1,2,3...
Change your initialization ofito: ``` int i[10] = {0,1,2,3,4,5,6,7,8,9}; ``` ...and callmaxArraywith justi; i.e.maxArray(i).