question
stringlengths
25
894
answer
stringlengths
4
863
I have seen references to 'zone' in theMsgPack C headers, but can find no documentation on what it is or what it's for. What is it? Furthermore, where's the function-by-function documentation for the C API?
msgpack_zoneis an internal structure used for memory management & lifecycle at unpacking time. I would say you will never have to interact with it if you use the standard, high-level interface forunpackingor the alternativestreamingversion. To my knowledge, there is no detailed documentation: instead you should refer...
I've added a entity framework model from a database using the wizard called EnterpriseDownloadRepository.edmx I can't access it when trying to set up the context in the same project. var context = new FileDownloadEntites() "FileDownloadEntites" is not recognized by visual studio 2012
found it in properties of the designer window. right click in a blank area of the designer window, select properties, and it is in a property called "Entity container Name"
I am using bool datatype in C std99 whose definitions are defined in<stdbool.h>. Now I want the user to give me input. What format specifier I must use in scanf to input the boolean value of 1 byte from the user and then manipulate it afterwards in my program.
There is none. Use a temp object as the size of_Boolis implementation dependent. ``` #include <stdbool.h> #include <stdio.h> bool b; int temp; scanf("%d", &temp); b = temp; ```
I've been experimenting with the performance of reading and writing files on Linux, specifically O_DIRECT, and I'm wondering, both at a hard drive level and the posix/Linux API level, is it possible to write only a few bytes to a sector, without destroying the rest of the sector, and without reading it first?
My experience with disk drives is that they expect data to be sent to them in entire sectors. So, basically, there's no way of writing less than an entire sector and if you wish to change the start of a sector without changing the end, youmustread the whole sector, modify and write back. That is partly to do with how ...
I am studying libev and ev_loop is a very important component of libev. But I searched through the libev source codes and just could not found the definition of struct ev_loop. So, how should the ev_loop look like? ``` struct ev_loop { /* anything here? */ } ```
Line 1501 of ev.c and all of ev_vars.h ``` struct ev_loop { ev_tstamp ev_rt_now; #define ev_rt_now ((loop)->ev_rt_now) #define VAR(name,decl) decl; #include "ev_vars.h" #undef VAR }; ```
I am just wondering why does copy_from_user(to, from, bytes) do real copy? Because it just wants kernel to access user-space data, can it directly maps physical address to kernel's address space without moving the data? Thanks,
copy_from_user()is usually used when writing certain device drivers. Note that there is no "mapping" of bytes here, the only thing that is happening is the copying of bytes from a certain virtual location mapped in user-space to bytes in a location in kernel-space. This is done to enforce separation of kernel and user...
I have written a C++ function to convert a string in markdown format to a string in html format wrapping the C library libmarkdown2 (Discount) on linux: ``` string markdown2html(const string& markdown) { auto m = mkd_string(&markdown[0], markdown.size(), 0); mkd_compile(m, 0); char* text; int len = ...
As far as I know the only thing that might not be re-entrant in Discount is themkd_initialize()function, though I did a small redesign in 2.1.{mumble} to try to keep the globals static.
Im trying to create a program using Windows sockets and i am getting an error code 0 when trying to create the socket ``` int iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); if (iResult != NO_ERROR) { wprintf(L"WSAStartup function failed with error: %d\n", iResult); } csocket = socket(AF_INET, SOCK_STREAM, IPPRO...
Theifcondition is wrong and the socket descriptor is actually being created as it does not equalINVALID_SOCKET. Change to: ``` if (csocket == INVALID_SOCKET){ wprintf(L"socket function failed with error: %ld\n", WSAGetLastError()); } ```
I find myself typing ``` double foo=1.0/sqrt(...); ``` a lot, and I've heard that modern processors have built-in inverse square root opcodes. Is there a C or C++ standard library inverse square root function that uses double precision floating point?is as accurate as1.0/sqrt(...)?is just as fast or faster than th...
No. No, there isn't. Not in C++. Nope.
Consider this code: ``` struct s { /* ... */ }; void f(struct s x) { /* ... */) /* (1) */ /* or */ void f(const struct s *x) { /* ... */ } /* (2) */ ``` Whenstruct shas a decent size, in which case should we prefer the first form?
Are you asking which is better? It depends what you are trying to do - the second form with a pointer will be more efficient. But if you just want to pass a value tofand not have to worry about side-effects then you might go with the first signature - as long as thestructis not too large.
Any way to convert a a 2 byte short (normal short) into just a 2 byte string (char*) after using htons on that short. The thing is that the htons method returns an int (4 bytes), how do I put it into a 2 byte string ??? Note: I need to be able to use ntohs on the result to get the original value. Thanks in advice :D...
Ahm, how do you say htons returns a 4-byte integer, on my linux, htons has the prototype of ``` uint16_t htons(uint16_t hostshort); ``` Thus you can do ``` uint16_t value; value = htons(hostshort); char *bytes = &value; // now the first 2 bytes pointed to by "bytes" are the value in network byte order ``` Which me...
I have seen references to 'zone' in theMsgPack C headers, but can find no documentation on what it is or what it's for. What is it? Furthermore, where's the function-by-function documentation for the C API?
msgpack_zoneis an internal structure used for memory management & lifecycle at unpacking time. I would say you will never have to interact with it if you use the standard, high-level interface forunpackingor the alternativestreamingversion. To my knowledge, there is no detailed documentation: instead you should refer...
I've added a entity framework model from a database using the wizard called EnterpriseDownloadRepository.edmx I can't access it when trying to set up the context in the same project. var context = new FileDownloadEntites() "FileDownloadEntites" is not recognized by visual studio 2012
found it in properties of the designer window. right click in a blank area of the designer window, select properties, and it is in a property called "Entity container Name"
I am using bool datatype in C std99 whose definitions are defined in<stdbool.h>. Now I want the user to give me input. What format specifier I must use in scanf to input the boolean value of 1 byte from the user and then manipulate it afterwards in my program.
There is none. Use a temp object as the size of_Boolis implementation dependent. ``` #include <stdbool.h> #include <stdio.h> bool b; int temp; scanf("%d", &temp); b = temp; ```
I've been experimenting with the performance of reading and writing files on Linux, specifically O_DIRECT, and I'm wondering, both at a hard drive level and the posix/Linux API level, is it possible to write only a few bytes to a sector, without destroying the rest of the sector, and without reading it first?
My experience with disk drives is that they expect data to be sent to them in entire sectors. So, basically, there's no way of writing less than an entire sector and if you wish to change the start of a sector without changing the end, youmustread the whole sector, modify and write back. That is partly to do with how ...
I am studying libev and ev_loop is a very important component of libev. But I searched through the libev source codes and just could not found the definition of struct ev_loop. So, how should the ev_loop look like? ``` struct ev_loop { /* anything here? */ } ```
Line 1501 of ev.c and all of ev_vars.h ``` struct ev_loop { ev_tstamp ev_rt_now; #define ev_rt_now ((loop)->ev_rt_now) #define VAR(name,decl) decl; #include "ev_vars.h" #undef VAR }; ```
I am implementing a decrypting mix-net in C using OpenSSL. I have encrypted the data using EVP_SealInit, EVP_SealUpdate, and EVP_SealFinal. I would then like to transfer this data over TCP to an open port (the first "mix"). Is EVP_SealInit, etc. the best way to go about encrypting a message string to be sent over T...
You need something that you can call a protocol. In its terms you will know when to send a data, when to send an IV, etc. IV can also be zero if your session key is random each time (EVP_Seal... provides that).
I need to convert some hi res audio files to u-law compression. I find no documentation on this- I'm almost certain the codec is there on Windows machines, but how the heck do I access it?
Yes the codec is there, however it is outside of WASAPI. APIs that deal with codecs are: Audio Compression ManagerDirectShowMedia Foundation Not sure about the latter, however the first two have the μ-law encoder readily available (the codec itself has ACM interface, and DirectShow offers awrapperover it).
Here is a snippet of some code. Instead of displaying the characters I am checking for, ╠ is displayed. ``` while (c!= EOF) { c = getc(fp); if (c==32 || c==33 || (c>=97 && c<=122) || c==35) j++; if(j==clns){ i++; j=0; mA[i][j]=c; } } for (i = 0; i < 10; i++) { for (j = 0; j < 20...
You are only ever writing tomA[i][0]: ``` if(j==clns){ i++; j=0; mA[i][j]=c; } ``` so you are printing random garbage that happened to be in the array. Move the assignment out of theif.
I have following structure ``` typedef struct List_Node { struct File_Descriptor *data; char *key; struct List_Node *next; }List_Node; ``` Now I inserted some values into the both the structures and want to access the data of type File_descriptor. How to do this? I tried this ``` struct List_Node *ln...
You just want: ``` struct List_Node *ln1; printf("%s", ln1->data); ``` struct File_Descriptoris the type.datais the struct member name. Also though theprintfformat looks entirely wrong. Not sure what you're trying to do there.%sis string, anddatacertainly doesn't look like a string.
I get this error in a C header file in this line : ``` char * getFechaHora(time_t & tiempoPuro); ``` In a C source code file i am including the header file and giving the function an implementation ``` char * getFechaHora(time_t &tiempoPuro){...} ``` also in my header file i am including correctly the "time.h" lib...
``` char * getFechaHora(time_t & tiempoPuro); ``` This is not C. C has no reference (&).
``` CC = gcc CFLAGS = -std=c99 -Werror VPATH = ./src:./include .MAIN: libstring.so .PHONY: clean libstring.o: libstring.c libstring.h $(CC) $(CFLAGS) -c $< -I ./include -o $@ libstring.so: libstring.o $(CC) -fPIC -shared $< -o $@ clean: rm -rf ./*.o ./*.so ``` In the code snippet above, I'm specifical...
Are yousureyou're using GNU make? The code you've written will work as you expect in GNU make. However, other versions of make do not support automatic variables in explicit rules, only in suffix (implicit) rules. If you're using SunOS/Solaris make, for example, then$<will be empty on an explicit rule.
In the absence of help from Google, I wonder if someone could tell me if it is possible to create a C++ (g++) debug macro that acts like, for example, an "improved" std::cout. Idea is to accept args via << and to append some text so that ``` DBG << "Hello" << world; ``` might produce ``` myfile.cpp 1420 Hello wor...
Your macro could create a temporary variable which invokesendlon destruction. The temporary will stick around until the enclosing expression ends, typically at the;. ``` #include <iostream> struct X { ~X() { std::cout << std::endl; } }; #define DBG (X(), std::cout << __FILE__ << " " << __LINE__ << " ") int main ...
In a directory tree (in C) I'm trying to connect parent directories to their child directories through a double pointer within the "dir" struct (struct dir **children) but I can't figure out how I would actually associate them syntactically, or "point to them." A code example would be great! Thanks
struct dir **childrenis not a "double pointer". It is a pointer to a pointer. To do what you want, you need to declarestruct dir *children[5]when 5 is the number of children you want to point to, or if you want it to be dynamic, alloc it withstruct dir **children = malloc(number_of_child * sizeof(*children)); then, ...
Is it possible to pass a message to the GNU build window from the source code? Something like: foo.c (not a makefile) ``` #ifdef DEBUG Echo "The Debug flag is set" // more code here ```
Look at the diagnostic pragmas in gcc: http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html e.g. GCC also offers a simple mechanism for printing messages during compilation. `#pragma message string` Prints string as a compiler message on compilation. The message is informational only, and is neither a co...
I have a string like this. ``` char array1[250] = {"Array Values are %d,%d,%d,%d"}; ``` And I have four integers like this, ``` int var1 = 25,var2 = 78, var3 = -189,var4 = -200; ``` I would like to print var1 to var4 in array1. How do I do that? I already have the format specifiers in array1 itself.
Don't put the format specifier in the array. Just do ``` char array1[128]; // enough space for four ints and the string sprintf(array1, "Array Values are %d,%d,%d,%d", var1, var2, var3, var4); ```
I thought that once a function returns, all the local variables declared within (barring those withstatickeyword) are garbage collected. But when I am trying out the following code, it still prints the value after the function has returned. Can anybody explain why? ``` int *fun(); main() { int *p; p = fun(); pr...
There's no garbage collection in C. Once the scope of a variable cease to exist, accessing it in any means is illegal. What you see is UB(Undefined behaviour).
First question: Is "unsigned" always the same as "unsigned int"?Is "signed" always the same as "int"?Is "short" always the same as "signed short"?Is ... Second question: If a C/C++ standard specifies answers to above questions, what paragraphs are related to them?
Yes, these are guaranteed. In C++11, see §7.1.6.2[dcl.type.simple]/table 10, which lists all of the simple type specifiers (and combinations thereof) and what they mean. For example, the table includes the following: ``` unsigned => unsigned int unsigned int => unsigned int signed => int signed int ...
I'm in the initial stages of designing an app that will connect to a remote server via ssh using the libssh2 library. One of the features I would like to have is the ability to be able to interact with a remote ncurses application. I understand that when connecting with libssh2 and executing a command, I will be retur...
So long as you're requesting a pty on the other end, your ncurses programs will be sending you lots of control sequences dictating cursor positions, colors, etc... What you're going to end up doing is writing a terminal emulator in order to interact with ncurses applications, so you might do some searching for vt100 t...
I would like to capture a MJPEG stream using C++. Which options do I have? I have tried OpenCV with FFMPEG support but icvCreateFileCapture_FFMPEG_p is always returning null (after a few seconds of timeout). May I program a HTTP client by myself? Regards,
M-JPEG is easy to capture. You send one HTTP request to the server and read back infinite response inmultipart/x-mixed-replaceformat (Content-Type). Then you split it into frames, which are self-contained JPEG files... Subheaders might or moight not contain additional information such as timestamps. You might find th...
i want to include value of i hex format in c. ``` for(i=0;i<10;i++) sprintf(s1"DTLK\x%x\xFF\xFF\xFF\xFF\xFF\xFF",i); ``` but the above code outputs an error: \x used with no following hex digits Pls any one suggest me a proper way....
Supposing you don't want to literally have\x00..\x0A, but the corresponding byte, you need ``` sprintf(s1, "DTLK%c\xFF\xFF\xFF\xFF\xFF\xFF",i); ``` while inserting\x%xwould be at the wrong abstraction level... If, OTOH, you really want to literally have the hex characters instead of the bytes with the named hey cha...
I am using functiongetopt_longto get command line options. I want to ignore error when a invalid option is given. Currently it printing error to stderr like: ``` invalid option -- 's' ```
There's variableopterrin getopt.h which will avoid printing the the error tostderrif you set it to 0. Just set it to 0: ``` extern int opterr; opterr = 0; ```
I am trying to work some image-process tasks with opencv on GPU with CUDA. I am using ubuntu. I setup my two products Opencv and Cuda without a problem, I am sure about that. However, when I attempt to run sampleCOde in eclipse, I have get an error: OpenCV Error: No GPU support (The library is compiled without CUDA s...
As stated in the documentation, you have to build OpenCV using CMake and set the flag WITH_CUDA=ON. Then you will get the full-featured OpenCV GPU module. Otherwise the module is still built, but you recieve an exception with CV_GpuNotSupported. For further information, read here:http://docs.opencv.org/modules/gpu/do...
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.Closed10 years ago. I am getting a value like this ```...
If there's no character that's value is 0xC3 in your data, you can traverse your data string, if an character that it's value equals 0xC3 occur, then remove the character and the next character.
The input consists a string and an integer, which are separated by a'/', like this: ``` hello/17 ``` And I want to read the input into a string and anint, like this: ``` char str[20]; int num; scanf("%s/%d", str, &num); // this how I tried to do it. ``` I can't seem to make it, any advice?
scanfawaits a whitespace terminated string when it tries to read%s. Try to specify the forbidden character set directly: ``` scanf("%19[^/]/%d", str, &num); ``` You can read more about the formating codeshere
I have created a static library with bulk of classes. I want use that static library in my current project. I want to avoid that bulk of .h files in my app. Is there any way to use only .a file.
There is no way that other user code could use your library if you don't tell it the interfaces that it may use. If you have a bulk of interfaces that you don't want to expose to the code that uses your library, you'd just have to structure it better. Create one singlemylib-interface.hfile that has all the interface...
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.Closed10 years ago. I can not solve this expression fro...
This is not the code but the way, you should expand a postfix to infix:: 5 x y - / x y + 3 ^ 7 / + 5 (x-y) / xy+ 3^ 7 / + (5/(x-y)) xy+ 3^ 7 / + (5/(x-y)) (x+y)3^ 7 / + (5/(x-y)) ((x+y)^3) 7 / + (5/(x-y)) (((x+y)^3) / 7) + (5/(x-y)) + (((x+y)^3) / 7)
I am implementing a decrypting mix-net in C using OpenSSL. I have encrypted the data using EVP_SealInit, EVP_SealUpdate, and EVP_SealFinal. I would then like to transfer this data over TCP to an open port (the first "mix"). Is EVP_SealInit, etc. the best way to go about encrypting a message string to be sent over T...
You need something that you can call a protocol. In its terms you will know when to send a data, when to send an IV, etc. IV can also be zero if your session key is random each time (EVP_Seal... provides that).
I need to convert some hi res audio files to u-law compression. I find no documentation on this- I'm almost certain the codec is there on Windows machines, but how the heck do I access it?
Yes the codec is there, however it is outside of WASAPI. APIs that deal with codecs are: Audio Compression ManagerDirectShowMedia Foundation Not sure about the latter, however the first two have the μ-law encoder readily available (the codec itself has ACM interface, and DirectShow offers awrapperover it).
Here is a snippet of some code. Instead of displaying the characters I am checking for, ╠ is displayed. ``` while (c!= EOF) { c = getc(fp); if (c==32 || c==33 || (c>=97 && c<=122) || c==35) j++; if(j==clns){ i++; j=0; mA[i][j]=c; } } for (i = 0; i < 10; i++) { for (j = 0; j < 20...
You are only ever writing tomA[i][0]: ``` if(j==clns){ i++; j=0; mA[i][j]=c; } ``` so you are printing random garbage that happened to be in the array. Move the assignment out of theif.
I have following structure ``` typedef struct List_Node { struct File_Descriptor *data; char *key; struct List_Node *next; }List_Node; ``` Now I inserted some values into the both the structures and want to access the data of type File_descriptor. How to do this? I tried this ``` struct List_Node *ln...
You just want: ``` struct List_Node *ln1; printf("%s", ln1->data); ``` struct File_Descriptoris the type.datais the struct member name. Also though theprintfformat looks entirely wrong. Not sure what you're trying to do there.%sis string, anddatacertainly doesn't look like a string.
I get this error in a C header file in this line : ``` char * getFechaHora(time_t & tiempoPuro); ``` In a C source code file i am including the header file and giving the function an implementation ``` char * getFechaHora(time_t &tiempoPuro){...} ``` also in my header file i am including correctly the "time.h" lib...
``` char * getFechaHora(time_t & tiempoPuro); ``` This is not C. C has no reference (&).
``` CC = gcc CFLAGS = -std=c99 -Werror VPATH = ./src:./include .MAIN: libstring.so .PHONY: clean libstring.o: libstring.c libstring.h $(CC) $(CFLAGS) -c $< -I ./include -o $@ libstring.so: libstring.o $(CC) -fPIC -shared $< -o $@ clean: rm -rf ./*.o ./*.so ``` In the code snippet above, I'm specifical...
Are yousureyou're using GNU make? The code you've written will work as you expect in GNU make. However, other versions of make do not support automatic variables in explicit rules, only in suffix (implicit) rules. If you're using SunOS/Solaris make, for example, then$<will be empty on an explicit rule.
In the absence of help from Google, I wonder if someone could tell me if it is possible to create a C++ (g++) debug macro that acts like, for example, an "improved" std::cout. Idea is to accept args via << and to append some text so that ``` DBG << "Hello" << world; ``` might produce ``` myfile.cpp 1420 Hello wor...
Your macro could create a temporary variable which invokesendlon destruction. The temporary will stick around until the enclosing expression ends, typically at the;. ``` #include <iostream> struct X { ~X() { std::cout << std::endl; } }; #define DBG (X(), std::cout << __FILE__ << " " << __LINE__ << " ") int main ...
In a directory tree (in C) I'm trying to connect parent directories to their child directories through a double pointer within the "dir" struct (struct dir **children) but I can't figure out how I would actually associate them syntactically, or "point to them." A code example would be great! Thanks
struct dir **childrenis not a "double pointer". It is a pointer to a pointer. To do what you want, you need to declarestruct dir *children[5]when 5 is the number of children you want to point to, or if you want it to be dynamic, alloc it withstruct dir **children = malloc(number_of_child * sizeof(*children)); then, ...
Is it possible to pass a message to the GNU build window from the source code? Something like: foo.c (not a makefile) ``` #ifdef DEBUG Echo "The Debug flag is set" // more code here ```
Look at the diagnostic pragmas in gcc: http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html e.g. GCC also offers a simple mechanism for printing messages during compilation. `#pragma message string` Prints string as a compiler message on compilation. The message is informational only, and is neither a co...
I have a string like this. ``` char array1[250] = {"Array Values are %d,%d,%d,%d"}; ``` And I have four integers like this, ``` int var1 = 25,var2 = 78, var3 = -189,var4 = -200; ``` I would like to print var1 to var4 in array1. How do I do that? I already have the format specifiers in array1 itself.
Don't put the format specifier in the array. Just do ``` char array1[128]; // enough space for four ints and the string sprintf(array1, "Array Values are %d,%d,%d,%d", var1, var2, var3, var4); ```
I thought that once a function returns, all the local variables declared within (barring those withstatickeyword) are garbage collected. But when I am trying out the following code, it still prints the value after the function has returned. Can anybody explain why? ``` int *fun(); main() { int *p; p = fun(); pr...
There's no garbage collection in C. Once the scope of a variable cease to exist, accessing it in any means is illegal. What you see is UB(Undefined behaviour).
First question: Is "unsigned" always the same as "unsigned int"?Is "signed" always the same as "int"?Is "short" always the same as "signed short"?Is ... Second question: If a C/C++ standard specifies answers to above questions, what paragraphs are related to them?
Yes, these are guaranteed. In C++11, see §7.1.6.2[dcl.type.simple]/table 10, which lists all of the simple type specifiers (and combinations thereof) and what they mean. For example, the table includes the following: ``` unsigned => unsigned int unsigned int => unsigned int signed => int signed int ...
I'm in the initial stages of designing an app that will connect to a remote server via ssh using the libssh2 library. One of the features I would like to have is the ability to be able to interact with a remote ncurses application. I understand that when connecting with libssh2 and executing a command, I will be retur...
So long as you're requesting a pty on the other end, your ncurses programs will be sending you lots of control sequences dictating cursor positions, colors, etc... What you're going to end up doing is writing a terminal emulator in order to interact with ncurses applications, so you might do some searching for vt100 t...
I would like to capture a MJPEG stream using C++. Which options do I have? I have tried OpenCV with FFMPEG support but icvCreateFileCapture_FFMPEG_p is always returning null (after a few seconds of timeout). May I program a HTTP client by myself? Regards,
M-JPEG is easy to capture. You send one HTTP request to the server and read back infinite response inmultipart/x-mixed-replaceformat (Content-Type). Then you split it into frames, which are self-contained JPEG files... Subheaders might or moight not contain additional information such as timestamps. You might find th...
Can anybody tell me when to use typedef in C? In the following code I get a warning bygcc: warning: useless storage class specifier in empty declaration ``` typedef struct node { int data; struct node* forwardLink; } ; ```
The syntax oftypedefistypedef <type> <name>; it makes the type accessible through thename. In this case, you've only specified atype, and noname, so your compiler complains. You probably want ``` typedef struct node { int data; struct node* forwardLink; } node; ```
``` int func(int arr[100][150], int rows, int columns); int func(int arr[100][150], int rows, int columns) { //stuff here } ``` This function works. What should I do if I would like to assign arr size to arr[rows][columns], but not 100 and 150 all the time? If I assign it to 100 and 150 it probably uses more memor...
Pass the dimensions first: ``` int func(int rows, int columns, int arr[rows][columns]) { … } ``` (Actually, the first dimension may be omitted. Dimensions after the first are needed to compute addresses.)
``` char* output= (char*) argv[2]; 92 fp = fopen(output, "w"); 93 if( fp = NULL ) 94 { 95 printf("writing output failed"); 96 return 0; 97 } 98 fprintf(fp,"hello"); ``` This is causing seg fault exc bad memory at line 98. What am I missing??
Your line ``` if( fp = NULL) ``` is assigning the value ofNULLtofp, instead of comparing. You should be using ``` if( fp == NULL) ```
I am writing a libnetfilter_queue program. I am new to linux kernel programming. I need to include linux/skbuff.h, net/checksum.h and many related kernel headers which are not present in /usr/include/linux. I get following error on compilation ``` fatal error: linux/skbuff.h: No such file or directory fatal error: n...
try thisfind / -name skbuff.h 2>/dev/nullthen when it finds the location use the-I/path/to/folderwhen you compile your program.. If it doesn't find the header you don't have it!
I try to use Eclipse to browse the Linux Kernel sources. How can I make Eclipse aware of what is set as build configuration in.configrespectively#defineed ininclude/linux/autoconf.h? I'm using Eclipse's Juno Service Release 1 (Build id: 20120920-0800) on Debian (stable). Useful would be something likegcc's option-i...
Take a look at this procedure to configure Eclipse to work with the Linux kernel.http://wiki.eclipse.org/HowTo_use_the_CDT_to_navigate_Linux_kernel_source
As far as I understand signals sent to a parent process should not be sent to children. So why does SIGINT reach both the child and the parent in the example below? ``` #include <stdio.h> #include <signal.h> #include <stdlib.h> #include <unistd.h> void sigCatcher( int ); int main ( void ) { if (signal(SIGINT, s...
If you are sending SIGINT by typing ^-C, the signal is sent to all processes in the foreground processing group. If you usekill -2, it will only go to the parent (or whichever process you indicate.)
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.Closed10 years ago. Please i'd like to modify: ``` f =...
I'd suggest this: ``` char filename[MAX_PATH]; snprintf(filename, sizeof(filename), "/home/%s.txt", argv[1]); f = fopen(filename, "w"); ``` Modifying thefopenis not a trivial task, though you can write a wrapper with the operations above.
I am currently messing around a bit with libvlc on android using the NDK. Well, I understand how to use native C code in an android app. Now I would like to use the libvlc library to make a simple player which would read data from a socket. Is it possible to use libvlc at that level? The problem I see is when it come...
You might be interested in this -https://bitbucket.org/tewilove/nyan.tv-jni/src Edit: Looks like the nyan.tv link doesn't exist anymore. A possibly more 'official' sample is here ->https://bitbucket.org/edwardcw/libvlc-android-sample
This is my code which is supposed to output prime numbers only. ``` #include <stdio.h> int prime(int n){ int j; for (j=2;j<=n/2;j++){ if((n%j)==0){ return 0; } else{ return 1; } } } void main(){ int i,p; for (i=2;i<=100;i++){ p=prime(...
Your probably want: ``` int prime(int n){ int j; for (j=2;j<=n/2;j++) if((n%j)==0) return 0; return 1; } ```
If I mark a variable as volatile I get a guaranteed read with each access in the code. But what about non-volatile variables? Is at least one read per function/block guaranteed, or can the value be optimized across function boundaries?
Why would function boundaries be important, if inlining (even un-provoked, i.e., noinline) could eradicate them anyway? I.O.W.: Yes, almost anything is possible under the as-if rule: As long as the program behaves as if the compiler hadn't optimized anything, it's allowed to do anything to it. (And the borders of tha...
hi there i have to remove a file at end of a C programme but i couldnt make it. i tried to use ``` execl("/usr/bin/rm","rm","example.txt",NULL); ``` but it isnt working. i will be appreciate if you can help and thanks anyway.
As other people pointed out, there are more efficient ways to remove a file. If you want to knowwhyyour program is failing, just run it understrace: ``` strace your-binary ``` You'll see all the system calls that your program does, with the corresponding return values. In this case, I strongly suspect thatrmis not ...
So, sometimes when I am programming in C through putty connected to a linux server, after executing my C file for testing, the command line will fill with the word "PuTTY" repeatedly 30 to 40 times. Sometimes it will display the word multiple times inside of my program. Anyone else have a similar problem? I am also d...
When PuTTY receives a Ctrl-E (character code 5), it outputs "PuTTY" (unless you've configured it to answer with something else). Sounds like your program's outputting some binary stuff. Whether that's intentional, i don't know.
``` #include <stdio.h> int main(int argc, char* argv[]){ printf("argc: %d\n",argc); for(int i=0;i<sizeof(argv);i++){ printf("argv[%d] %s\n",i,argv[i]); } return(0); } ``` compiles fine, when using it under a gnome terminal under a GNU/linux distribution ``` printTest one\ two three argc: 3 argv[0] /data...
sizeof(argv)is meaningless -- it's the size of a pointer (4 on your platform), which just coincidentally happens to be one more than the number of values inargvin this case. Useargchere instead.
I want to check if number has all even or odd bits set to one and only them. For eg.: Number42is correct, because in a binary code101010it has all and only even bits sets to1. Number21is also correct,10101. Number69for eg.1000101is not correct, because there are only three odd bits sets to1. I've tried using differ...
Those numbers have that property that(x ^ (x >> 1)) + 1is a power of 2. Andyis a power of 2 ify & (y - 1) == 0 So one test could be((x ^ (x >> 1)) + 1) & (x ^ (x >> 1)) == 0which would work for numbers of any size.
I am new in C program and linux, how can we compile and run this program? I have triedgcc example.cthen./a.outbut it gives an error likeinput file cannot be opened( I have written this error in the read method) ``` // example.c int main(int argc, char *argv[]) { char* input = argv[1]; read(input); char*...
Your program isn't going to work very well - you're not providing enough arguments toreadandwrite, for example (assuming you mean to be calling POSIXread(2)andwrite(2), that is). To answer your actual question, the problem appears to be that you're not providing any arguments. You need to run it something like: ```...
Hello a friend of mine shown me this piece of code to make a point about array/stack bound checking. ``` #include <stdio.h> void foo() { unsigned long long a[1]; a[3] -= 5; printf("Print me!\n"); } int main(){ foo(); return 0; } ``` When I run this code, it keeps printing "Print me!\n"...
You damage thread stack by commanda[3] -= 5;because changing var out of array range. The behavior is totaly unpredictable and can be different on other systems. I think you just modify return address on stack to call printf If you want to understand - use disassembler.
For some reason I have to link glibc manually. I am trying to run the following program: ``` #include <stdio.h> int _start(){ printf("ABCDE"); return 0; } ``` In order to compile it I type the following commands: ``` gcc -c main.c -o main.o gcc -L/lib/x86_64-linux-gnu/ -nostdlib main.o -o main -lc ``` Unfo...
an_exit(0);should do the trick. However, what are you trying to achieve?Sample
This question already has answers here:Closed10 years ago. Possible Duplicate:Why do I get a segmentation fault when writing to a string? If I have a pointer and I know the indexes of both the chars, how would I swap the chars(I didn't actually allocate an array) i.e. char *str = "hello"and I know and I wanted to ...
Well, you can't with pointer to a string literal. Literals are immutable. Stick with the way you've always done it.
For educational reasons I have to exploit an C-Code The Programm set the egid first, and then the vulnerability with thesystem("/usr/bin/...");Command. So I made an 'usr' executeable in my Home-Directory and set the Path to the HomePATH=$HOME:$PATH And I want to change the IFS Variable in the bash to /:export IFS='...
Add the IFS as part of your program's call tosystem(). System executes the code with/usr/bin/sh -c. So you can do similar to what you'd in the shell prompt. ``` system("export IFS='/'; /usr/bin/cmd"); ``` Note that once the child process is terminated, the IFS set will no longer be available in the parent.
For example if my program name istest.c Then for the following run command theargc = 2instead of4. $test abc pqr* *xyz*
Try to run: ``` $ echo abc pqr* *xyz* ``` and you will understand why you don't get theargcvalue you were expecting
The number of tokens in the following C statement. ``` printf("i = %d, &i = %x", i, &i); ``` I think there are 12 tokens here. But my answer is wrong. Can anybody tell me how to find the tokens in the above C statement? PS: I know that a token is source-program text that the compiler does not break down into compo...
As far as I understand C code parsing, the tokens are (10 in total): ``` printf ( "i = %d, &i = %x" , i , & i ) ; ``` I don't count white space, it's generally meaningless and only serves as a separator between other tokens, and I don't break down the string literal into pieces, because it's an integral entity of it...
I have the following line which sends the argumentsargs[]andlengthto a method calledlargest. ``` printf("Largest is: %d \n", largest(args[], length)); ``` When i try to run this i get the following error: error: expected expression before ']' token
because you need to place an integer between the operator square brakets, or otherwise don't specify the square brackets : ``` printf("Largest is: %d \n", largest(&args[0], length)); ``` or ``` printf("Largest is: %d \n", largest(args, length)); ``` Keep in mind thatargs[0]is the same as*(args + 0)butargs[]will gi...
I filled out the WNDCLASS and the the hbrBackground property to my bitmap like wc.hbrBackground = CreatePatternBrush( LoadBitmap( hInstance, MAKEINTRESOURCE( "grey-texture.bmp" ) ) ); This doesn't seem to change at all, the window is white like it is for defaults, so I need to find out what is going on here. Is Crea...
See the following pages: http://msdn.microsoft.com/en-us/library/windows/desktop/dd162462(v=vs.85).aspx http://msdn.microsoft.com/en-us/library/windows/desktop/dd183508(v=vs.85).aspx http://msdn.microsoft.com/en-us/library/windows/desktop/ms633576(v=vs.85).aspx There are two types of brushes, logical and physical....
I have this matrix: ``` 1 2 3 4 5 6 7 8 9 A B C D E F 0 1 2 3 4 ``` And I want it printed in one line as following: ``` 1 6 2 B 7 3 0 C 8 4 1 D 9 5 2 E A 3 F 4. ``` How is the easiest way to do that?
use a nested loop. outer loop is over the distance from (0,0) inner loop over all valid combinations of i and j that sum up to the distance.
I can't understand why doespthread_jointakes as 2nd argumentvoid**for the return value, whereaspthread_exit, which is given the return value, has the return value argument asvoid*.
pthread_join waits for the thread to end, and the resulting value from pthread_exit is stored into *value_ptr. If you want to ignore the result, you can pass NULL for the value_ptr. This is the common C practice of simulating pass by reference by passing a pointer to a variable. SeePassing by reference in C The pthre...
I wonder why when I try to declare the array using#defineI get errors from compiler, while using literal instead of the size allows me to do so. some_name.h: ``` #define size 10; int* waitingBench[size]; ```
What you have will be pre-processed to: ``` int* waitingBench[10;]; // ^ notice this guy! ``` Remove the semicolon from the#define. (Andsizeis a really bad identifier to#define.)
I have a program with 2 threads. I want the first thread to be run under user permissions of USER_1, and the second under USER_2 of Windows. When I log in as USER_1, both threads have USER_1 permissions. How can I change the user of the thread!?
You need to assign an impersonation token to a thread usingSetThreadToken(). It may not be very trivial to do, though.
I am trying to map the value of ananalogReadfrom a potentiometer between 0-1. So I do: ``` float inverse_value = 1.0f / (float)analogRead( pot_pin ) ``` But when the analogRead of the potentiometer is at 0, the inverse is 0 (which is correct), but when theanalogReadis at 1023, the inverse becomes0.0009775170. Am I ...
What you want to do, is probably this: ``` float inverse_value = (float)analogRead(pot_pin) / 1023.0f; ``` Assuming the max position is 1023. That way, 0 to 1023 will be mapped as 0 to 1. For example, when the potentiometer is in the middle position (512), it becomes this: ``` float inverse_value = 512.0f / 1023....
I need to extract all meta data along with play-length information from the video files in pure C . I goggled and found MediaInfo Library but was not able to find any relevant c sample code . Is there any other way to achieve this with / without MetaInfo ? Or can somebody point me to a good sample code of MediaInfo...
ffprobe which is part of ffmpeg can do a whole lot more. ffprobe without switches will give some common information It also has lot of switches of which you can use one at a time [exclusively] -show_format show format/container info-show_streams show streams info-show_packets show packets info-s...
This question already has answers here:Closed10 years ago. Possible Duplicate:C: How come an array’s address is equal to its value? ``` int a[2]; printf("%u %u", (int)(&a), (int)(a)); ``` I am thinking that&ais a pointer that points to the address ofa. And the secondameans the beginning address of the array. Why a...
In any context except where it is the operand of either the unary&orsizeofoperators, the array nameaevaluates to a pointer to the first member of the array. This has typeint *. In&a,astill designates the array itself, so&ais the addressof the array. This has typeint (*)[2]. Since the first element of the array is ...
I was trying to make a simple c calculator because i am a newbie and thought it would be a good idea. This is my code: ``` #include <stdio.h> main() { char b; int a,c,d; printf("Please enter your first number: "); scanf("%d",&a); printf("Please enter your second number: "); scanf("%d",%c); printf("Enter your o...
Change the%to a&in thescanf: ``` scanf("%d", &c); ^ ``` Also, instead ofmainyou wantint mainand you probably should return something at the end.
I was trying to build a very simple program in C that returns a float value from a function, but for some reason I got an error. ``` #include<stdio.h> int main(){ double returning; returning = regre(); printf("%f", returning); return 0; } double regre(){ double re = 14.35; return re; } ``` Th...
That error message is telling you exactly what's happening - there is an implicit declaration ofregrebecause you don't define it until aftermain(). Just add a forward declaration: ``` double regre(); ``` Beforemain(), or just move the whole function up there.
So I have multiple threads which will be using the rand_r function. The signature of this function is : ``` int rand_r(int *val); ``` I was trying to use the time to seed this function but I'm having all kinds of trouble. Could anyone explain to me how I would call rand_r using time, or some other simple way to seed...
For the reentrant versionrand_r, the seed is just the initial value of the state .You need one seed per thread. Either create an array of seeds, or make the seed variable thread-local: ``` _Thread_local unsigned int seed = time(NULL); int do_stuff() { for ( ; ; ) { int n = rand_r(&seed); // u...
Can somebody please explain to me why the below code got the "invalid operands to binary ==" error? ``` typedef int (*func_t)(int); #define NO_FUNC ((func_t) 0) struct { const char *name; func_t func; } table[] = { {"func1", NO_FUNC} }; if (table[0] == NO_FUNC) { // invalid operands to binary == } ```
And you should refer to the correct member in the struct: ``` if (table[0].func == NO_FUNC) ```
Hi I'm new to dealing with bytes and low level programming. Currently, I have an int (32 bits)....so it looks something like this: ``` 0000000 10011011 00000000 00000000 ``` I'm trying to output ONLY the 3rd set of 0's with the 1's (counting from the right). So I'd be outputting a char value (?) How can I do that?...
You can shift the bits right by 16 and then & it with 0x000000FF to clear all of the bits except the desired ones. ``` int i = 0b0000000100110110000000000000000; char c = (i >> 16) & 0xFF; printf("%c\n", c); ```
I just started with C, but I had some knowledge of PHP, so I decided to do some 'more complicated' stuff, as for a beginner :) I used two nested loops to print an 50x50 array. It isn't very slow, but I included a movement with arrow keys to it to move one symbol, X (player) around the array. Every time a move is made...
You would probably have to use some sort of shell graphics library likencursesto move stuff around your array without it blinking when you redraw it. There's not really a simple way to avoid that when you're just using printf to display your grid as output.
If there a way to insert custom parameters into the GOST 2001 parameters set programmatically and what API should be used? After being managed to generateEVP_PKEYby simulating OpenSSLs' function I found out that parameters are bound to NID, so there's a need in adding custom ones there. Ideas anyone?
Problem solved next way: Upper errorFILL_GOST2001_PARAMS:unsupported parameter setappears if you don't set yourCurveNameas one of already existing parameter set NID, so it should be like this:EC_GROUP_set_curve_name(CurveGroup,NID_id_GostR3410_2001_TestParamSet).However setting one for default parameters set doesn't ...
I cannot find what's wrong in this simple array initialization. The program crashes with a segfault onfield[x][y] = ' ';, x and y at 0 (I use Code::Blocks debugger) ``` /* init data structures */ char **field; int field_width=5,field_height=5; field = malloc(sizeof(char*)*field_width); for(x=0;x<field_width;x++) { ...
``` field = (char*) malloc(sizeof(char*)*field_width); ``` Thechar*cast maybe?
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.Closed10 years ago. I've made topic for vim alreadyRead...
You can have a look atEmacs Prelude. Prelude is an enhanced Emacs 24.x configuration that features a lot of sensible defaults, additional 3rd party packages and powerful setups for most popular programming languages. It's very modular and has the nice ability to auto-install some packages on demand - for instance the...
In the Arduino IDE, I'd like to add the contents of two existing arrays like this: ``` #define L0 { {0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 0, 0} } #define L1 { {0, 0, 0, 1}, {0, 0, 0, 0}, {0, 0, 0, 0} } ``` should become ``` int myarray[3][4] = { {0, 0, 0, 1}, {0, 0, 0, 1}, {0, 0, 0, 0} } ``` How would I go about this...
Thy this; ``` const int a[3][4] = { {0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 0, 0} }; const int b[3][4] = { {0, 0, 0, 1}, {0, 0, 0, 0}, {0, 0, 0, 0} }; int c[3][4]; const int* pa = &a[0][0]; const int* pb = &b[0][0]; int* pc = &c[0][0]; for(int i = 0; i < 3 * 4; ++i) { *(pc + i) = *(pa + i) + *(pb + i); } ```
To create a class usable in Python is pretty straight-forward:http://code.activestate.com/recipes/54352-defining-python-class-methods-in-c/ But how to make methods static?
Use theMETH_STATICflag inPyMethodDef. The method will be passed NULL as the first parameter rather than an instance of the type. ``` static PyMethodDef FooMethods[] = { {"__init__", Foo_init, METH_VARARGS, "doc string"}, {"doSomething", Foo_doSomething, METH_VARARGS | METH_STATIC, "doc string"}, ...
I need the send and integer to a function and then append that to the end of a constant character. ``` int main (void) { append(1); } int append(int input) { const char P = 'P'; //This where I want to append 1 to P to create "P1"' } ```
No matter what you do, you need to convert the number to a string, otherwise you can't create a string containing both numbers. You can actually combine both the concatenation and the int-to-string conversion in one function call:sprintf: ``` char output[16]; sprintf(output, "P%d", input); ```
I'm currently writing a C function that return a time_t value but I need to manage error cases (because this function uses I/O functions) too. Is it correct to use (time_t) -1 as an error indicator?
Using(time_t)-1is already used bytime()function to report a failure so does not seem an unreasonable choice: Current calendar time encoded as time_t object on success, (time_t)(-1) on error. If the argument is not NULL, the return value is equal to the value stored in the object pointed to by the argument. However, ...
This question already has answers here:Closed10 years ago. Possible Duplicate:Typedef function pointer? Could you please help me understand the meaning of this typedef and how to use it? ``` typedef void (*__handler)(int) ``` without the "typedef", I know the rest is a function pointer. Thank you.
This defines a type name for the function pointer. Using this,__handleris now a type alias for a pointer to a function that takes anintand returnsvoid. ``` void myFunction(int) { // ... } int main(int argc, char **argv) { __handler functionPtr = &myFunction; // ... } ```
How can I detach an executable file from its process using WinAPI (C/C++)? I found an application that releases files from processes, Unlocker, but I don't know how that works.
You don't, normally. Windows pages in your executable on-demand. When you call a function which isn't in RAM yet, Windows loads it (and the whole page it resides on). As a result, if you would detach the EXE and the process would call a function that's still on disk, the process would crash. For applications on remo...
How do I specify in my makefile that I want to link with thelibtifflibrary. Just specifying -ltiff in LDFLAGS is not working.
Either you can use the -L flag (see either manual for the compiler - I am assuming that you are using gcc or g++ or Set the environment variableLD_LIBRARY_PATHto include the path for the library But you should also consider static or dynamic linking. The documentation for both compilers are very good to explain how...
i have developing a C++ Api project. i will use dialogboxparam to create a dialogbox... i done to create and set the textbox,labels and buttons... its work fine... now i want to add a image in the top of the dialogbox... i did use this code in WM_INITDIALOG: ``` HBITMAP hImage= (HBITMAP)LoadImage(NULL,L"C:\\WI...
The easiest way is to override the WM_PAINT for the window and paint the bitmap at that point (between the BeginPaint and EndPaint) calls There is an MFC based example here: http://www.programmersheaven.com/mb/mfc_coding/113034/113034/how-do-i-set-a-background-picture-in-a-dialog-box-/
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.Closed10 years ago. I've made topic for vim alreadyRead...
You can have a look atEmacs Prelude. Prelude is an enhanced Emacs 24.x configuration that features a lot of sensible defaults, additional 3rd party packages and powerful setups for most popular programming languages. It's very modular and has the nice ability to auto-install some packages on demand - for instance the...
In the Arduino IDE, I'd like to add the contents of two existing arrays like this: ``` #define L0 { {0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 0, 0} } #define L1 { {0, 0, 0, 1}, {0, 0, 0, 0}, {0, 0, 0, 0} } ``` should become ``` int myarray[3][4] = { {0, 0, 0, 1}, {0, 0, 0, 1}, {0, 0, 0, 0} } ``` How would I go about this...
Thy this; ``` const int a[3][4] = { {0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 0, 0} }; const int b[3][4] = { {0, 0, 0, 1}, {0, 0, 0, 0}, {0, 0, 0, 0} }; int c[3][4]; const int* pa = &a[0][0]; const int* pb = &b[0][0]; int* pc = &c[0][0]; for(int i = 0; i < 3 * 4; ++i) { *(pc + i) = *(pa + i) + *(pb + i); } ```