question
stringlengths
24
425
answer
stringlengths
5
405
Hi I am working with a matrix of 448*448 elements of real(signed) data and wanted to display it as grayscale image in C as i did in MATLAB usingimagesc. Can anyone tell me which is the fastest and easiest library or code to display the grayscale image from the matrix in C? Thanks.
Also look atopenCVlibs. These libs are quite good. It has both c and C++ interface.
I would like to define/generate a GUID (interface class) for my test driver. What is the best way to do that 'programatically using C/C++' so it won't conflict with other devices/drivers in the system? Also, are there any standard guidelines to follow or other things to keep in mind while creating a new GUID? Please suggest.
Use a GUID generator. There is one bundled with Visual Studio. In 2008, it's under Tools > Create GUID.
I'm trying to test C code with googletest but I'm having some problems when my C header files are included in the C++ test file because the g++ compiler handle them as C++ headers. I've tried to include these headers insideextern "C" {}with no success. Is there a way g++ compiler can handle these headers as C ones?
extern "C" only changes link stage name mangling. If you are using C features that aren't shared by C++ then you are SOL
I would like to ask, how to call a shell script with parameters in C. I have found this, but it seems not working. ``` #include <stdio.h> #include <stdlib.h> char script = "script.sh"; system(script); ``` Thanks in advance!
``` const char * script = "script.sh"; ``` instead of ``` char script = "script.sh"; ``` Note the «*» sign... thesystemfunction needs achar *, not a single char (a string, not a character).
What is the easiest way to get the UUID of a hard drive partition programmically in Linux? (Using C)
Uselibblkidfrom theutil-linux-ng distribution. It includes somesample code. (Your system probably already has a "blkid" utility linked against some version of libblkid.)
In PHP API we could usecurl_setopt($curl, CURLOPT_RETURNTRANSFER, true);but how to translate it into C? I triedcurl_easy_setopt(curl_handle, CURLOPT_RETURNTRANSFER, true);but failed.
There's noCURLOPT_RETURNTRANSFERin libcurl C API. You can do that with a callback function, it's one oflibcurls examples:get a remote file in memory only.
I've written Unix Pipes but I don't have the good result. I'm wondering if it's possible to debugging Unix pipe in C langage with gdb. If no, do you know a method to do that ? thanks in advance.
Use netcat with the -U switch. You will be able to create a listen/sender, or sit in between.
What does following declaration mean in C? ``` char a = (10,23,21); ``` While printing the value of "a" with "%u" the output is 21.gccis not giving any error. What's this kinda declaration and what's the use of it?
You are seeing the comma operator at work. The comma operatora,bevaluatesa, throws away the result, then returnsb. Since10and23have no side effects, this is equivalent tochar a = 21;
I can't see anyalloca.hequivalent inVisual C 2010. How can one perform stack allocation inVisual Con Windows? I miss the functionalloca.
See_alloca. Visual C uses an _ prefix for non-standard functions in the C headers.
Basically the title is self explaining. I'm programming in C and i use fgets as the input function but i do not want that control characters get printed.
fgets()is rather simple, and doesn't offer you much control over what appears on the screen. I don't think that it's possible to do this. You may want to look into something more powerful - likereadline.
I've written Unix Pipes but I don't have the good result. I'm wondering if it's possible to debugging Unix pipe in C langage with gdb. If no, do you know a method to do that ? thanks in advance.
Use netcat with the -U switch. You will be able to create a listen/sender, or sit in between.
What does following declaration mean in C? ``` char a = (10,23,21); ``` While printing the value of "a" with "%u" the output is 21.gccis not giving any error. What's this kinda declaration and what's the use of it?
You are seeing the comma operator at work. The comma operatora,bevaluatesa, throws away the result, then returnsb. Since10and23have no side effects, this is equivalent tochar a = 21;
I can't see anyalloca.hequivalent inVisual C 2010. How can one perform stack allocation inVisual Con Windows? I miss the functionalloca.
See_alloca. Visual C uses an _ prefix for non-standard functions in the C headers.
Basically the title is self explaining. I'm programming in C and i use fgets as the input function but i do not want that control characters get printed.
fgets()is rather simple, and doesn't offer you much control over what appears on the screen. I don't think that it's possible to do this. You may want to look into something more powerful - likereadline.
I need to know how to make this ignore the number 0 when 0 is input so that the program does not exit when 0 is input. ``` #include <stdio.h> int main() { int input = 0, previous = 0; do { previous = input; printf("Input Number"); scanf("%d", &input); } while( input!= previous*2 ); return 0; } ```
Pick a different value forprevious. TryINT_MAX >> 1from limits.h.
I need to install VSE (2010, I guess) Java. Will that installation screw up my currently-installed VSE 2008 C/C++ in any way? Thanks!
Do you mean J# or something like that by any chance? I would say no. I don't use the express editions myself, but have various versions of visual studio on my machine that happily coexist.
I want to write a C or C++ program, that given an IP address, Pings it and then performs further action based on whether the Ping was successful or not. How to do this?
Have a blast atThe Ping Page, which has a link tofull sourceon the original Unixping(8).
Why does the following code run the while loop? I thought "mid = term" is an assignment, not a condition? Please explain. Thanks. ``` #include <stdio.h> main () { int mid = 4, term = 4; while ( mid = term) printf("%d\n", --term); } ```
The result of an assignment is the value. Therefore the expression evaluates to4or a non-zero and thus, in C,TRUE.
This is probably a really stupid question, but how do I turn on these debug messages in my code? ``` #ifdef DEBUG_MSG printf("initial state : %d\n", initial_state); #endif ``` Many thanks in advance,
When compiling, try something like this: ``` $ gcc -DDEBUG_MSG -o foo foo.c ```
I need to install VSE (2010, I guess) Java. Will that installation screw up my currently-installed VSE 2008 C/C++ in any way? Thanks!
Do you mean J# or something like that by any chance? I would say no. I don't use the express editions myself, but have various versions of visual studio on my machine that happily coexist.
I want to write a C or C++ program, that given an IP address, Pings it and then performs further action based on whether the Ping was successful or not. How to do this?
Have a blast atThe Ping Page, which has a link tofull sourceon the original Unixping(8).
Why does the following code run the while loop? I thought "mid = term" is an assignment, not a condition? Please explain. Thanks. ``` #include <stdio.h> main () { int mid = 4, term = 4; while ( mid = term) printf("%d\n", --term); } ```
The result of an assignment is the value. Therefore the expression evaluates to4or a non-zero and thus, in C,TRUE.
This is probably a really stupid question, but how do I turn on these debug messages in my code? ``` #ifdef DEBUG_MSG printf("initial state : %d\n", initial_state); #endif ``` Many thanks in advance,
When compiling, try something like this: ``` $ gcc -DDEBUG_MSG -o foo foo.c ```
Is there anyway given a string like,"my example\n", to get a pointer to it? For instance,&"my example\n"or&{"my example\n"}? EDIT: I guess asking rudimentary questions is what I get for not sleeping last night. Ah well, thanks for all your help anyway.
It's already a pointer: ``` char *string = "my string\n"; ``` stringwill be a pointer to the literal string.
How can I convert 1.bmp 2.bmp ... n.bmp (each 24 bpp) into a single mng or apng file (with animation) in bash/cpp?
This program can create APNG from TGA/PNG sequences: http://sourceforge.net/projects/apngasm/files/
I am trying to write a small music manager in Linux using C++. I am currently using TagLib to read the media's metadata. However, as far as I know, TagLib does not support reading tags (title, artist, etc...) from a video. Therefore, I just want to ask you guys if there is any other library I can use to read the tags (title, artist, etc...) of a video file? Thank you for answering my question! You guys have a good week!
MediaInfolibrary
I was wondering if anyone knew of a way that I could feed an image file to a Python, C or Java program and get back the coordinates of where a specific string appears on the image?
What you're talking about is calledOptical Character Recognition, or OCR. OCR isn't easy to implement from scratch, but there are libraries out there.OpenCV can be used for OCR.
I was wondering if anyone knew of a way that I could feed an image file to a Python, C or Java program and get back the coordinates of where a specific string appears on the image?
What you're talking about is calledOptical Character Recognition, or OCR. OCR isn't easy to implement from scratch, but there are libraries out there.OpenCV can be used for OCR.
Has anyone usedccccwith pure C code? I tried it and it seems to handle all the files as one module, which means that most of the counters are useless (e.g. there is no fan-in or fan-out since there is just one module). Can I somehow tell it to do this comparison on a file-by-file basis (i.e. each file is one module)?
Seems a little bit outdated. I usually usesloccountwith good results.
When you are printing a tab character to the standard output usingprintfin C, it outputs some space which is apparently 4 characters in length. ``` printf("\t"); ``` Is there a way by which I can control the tab width in the above case?
That's something controlled by your terminal, not byprintf. printfsimply sends a\tto the output stream (which can be a tty, a file, etc.). It doesn't send a number of spaces.
How does the following piece of code work, in other words what is the algorithm of the C preprocessor? Does this work on all compilers? ``` #include <stdio.h> #define b a #define a 170 int main() { printf("%i", b); return 0; } ```
The preprocessor just replacesbwithawherever it finds it in the program and then replacesawith170It is just plain textual replacement. Workson gcc.
If I use ntohl() on an integer which is already in host byte order will that cause any problems? If not, how does the ntohl() function know its argument is already in host byte order?
Your question doesn't make any sense. Forntohlnothing is high-order or low-order. If the endianness of the system is the same as network order, it will do nothingOtherwise it will swap stuff around
Is there a way to have one raw input buffer per device? So I would like to have a buffer for mouse and another one for keyboard. Is it possible?
Yes, trySetWindowsHookEx. You will have to convert WM_KEY* messages to WM_CHAR yourself, though.
``` #include < stdio.h > int main() { char *s; s=call(); printf(s); } char* call() { return("hello"); } ``` Why these code not working. It's generating an error. How do I make it work?
Two things: You can't put spaces inside the angle brackets when including a system header (e.g.#include <stdio.h>You need a prototype forcall()
By default, GDB always prints/displays all variables / arguments in base 10. Is there any way to ask GDB to always use base 16 while printing anything (and turn back to default settings when I don't need that)? I know that it can be printed by supplying the/xargument to print/display, but I don't want to do it every time.
set output-radix 16(andset output-radix 10to switch it back).
popenstores o/p of the specified command into a file. How can I get similar functionality but o/p into a variable (i.e. in a char*) ?
No,popen()does not store output into a file. It specifies astream, whichmightrepresent to a file on disk but which might also be at e.g. a pipe or socket. Streams are more abstract than files. To have a pipe, you would open the pipe using e.g.pipe()and then callfdopen()on the proper end of the resulting pipe.
``` #include < stdio.h > int main() { char *s; s=call(); printf(s); } char* call() { return("hello"); } ``` Why these code not working. It's generating an error. How do I make it work?
Two things: You can't put spaces inside the angle brackets when including a system header (e.g.#include <stdio.h>You need a prototype forcall()
By default, GDB always prints/displays all variables / arguments in base 10. Is there any way to ask GDB to always use base 16 while printing anything (and turn back to default settings when I don't need that)? I know that it can be printed by supplying the/xargument to print/display, but I don't want to do it every time.
set output-radix 16(andset output-radix 10to switch it back).
popenstores o/p of the specified command into a file. How can I get similar functionality but o/p into a variable (i.e. in a char*) ?
No,popen()does not store output into a file. It specifies astream, whichmightrepresent to a file on disk but which might also be at e.g. a pipe or socket. Streams are more abstract than files. To have a pipe, you would open the pipe using e.g.pipe()and then callfdopen()on the proper end of the resulting pipe.
I want to suspend (pause) a forked process at startup and resume it later on. Is there any way to do that with POSIX or Solaris.
Why not just callpause()in code of child process after fork?
Stumbled upon this example of bad C++ code in a blog post, without any explanation as to why it is considered "bad". I have my own ideas, but would like to hear experienced C++ devs on this. ``` unsigned int Fibonacci (unsigned int n) { if (n == 0 || n == 1) return n; else return Fibonacci (n - 1U) + Fibonacci (n - 2U); } ```
Perhaps because it runs in exponential time?
I have for loop doubt that I need to ask . once i saw in coding something like ``` for(i = 0; i<10; i+) ``` My doubt is why &when in for loop we use sayi+ori-rather thani++ori-- Thanks in advance
It won't work, doesn't the compiler return an error if you do? ( or atleast a warning.. ) Just use ++i or i++
What is the best way to generate UTF-8 JSON in C? I've looked atJansson, but it seems extremely bulky. Is there any other good low-dependency library for creating and reading JSON objects/strings in C?
Perhaps the JSON module from CCAN?http://ccodearchive.net/It doesn't even depend on anything else from CCAN, and consists of exactly two filesjson.candjson.h (The JSON module is herehttp://git.ozlabs.org/?p=ccan;a=tree;f=ccan/json)
I'm using EXTRA_DIST within a Makefile.am to copy some folders: EXTRA_DIST = input/ The problem is that it repeats the directory name input/input/ Do you know any solution for this problem? is this a bug of automake?
I have found the solution. With: "EXTRA_DIST = input" instead of "EXTRA_DIST = input/" works fine
When a terminal disconnects, kernel will notify controlling terminal by sending aSIGHUPto it. After that, controlling process sendsSIGHUPto all processes in the same session. What happens when those processes catch theSIGHUPbut do some other thing instead of terminating in signal handler?
They go on with their business and terminate When they decideWhen they receive another signal
hello i have to download a simple .txt file from web in c language. i have found a way with curl (tut) but now i want to know other ways. my application should check the content of file and return it. filecontent: ``` open ``` or ``` closed ``` Does someone knows any tutorials or codesnippets?
You need a tutorial about sockets and have to look up the HTTP spec. It's pretty simple.
I'm executing aDELETEstatement using the SQLite 3 C API, and I'd like to know how to fetch the number of affected rows. Unfortunately, there is no function such assqlite3_affected_rowsor similar.
Trysqlite3_changes()and/orsqlite3_total_changes()
The application runs in Linux, Windows, Macintosh. Also, if yes, how much effort is required?
Does nginx run on windows? I think you'd have a much better result using an existing library that includes a good http server. My first choice would belibevent.
I have a C code that collects data and places them in a 2-D array. I would like to plot this data on an x-y graph (mathematics) automatically i.e. pass the data as parameters in a command line and get a graph Are there any suggestions for how to do so?
gnuplot is a good one to look at assume you mean x-y charts, if you want actual graphs then look at dot
hello i have to download a simple .txt file from web in c language. i have found a way with curl (tut) but now i want to know other ways. my application should check the content of file and return it. filecontent: ``` open ``` or ``` closed ``` Does someone knows any tutorials or codesnippets?
You need a tutorial about sockets and have to look up the HTTP spec. It's pretty simple.
I'm executing aDELETEstatement using the SQLite 3 C API, and I'd like to know how to fetch the number of affected rows. Unfortunately, there is no function such assqlite3_affected_rowsor similar.
Trysqlite3_changes()and/orsqlite3_total_changes()
If you had to convert ``` unsigned short data1[32] ``` to ``` unsigned char* data2 ``` in a tight loop to be executed 10 million times what function would you use to get the best performance?I am using this ``` reinterpret_cast<unsigned char*>(data1); ``` but was wondering if there is a better way
reinterpret_castis the holy grail of performance seeking coders, namely code that results in zero clock cycles.
I know I can get file size ofFILE *byfseek, but what I have is just a INT fd. How can I get file size in this case?
You can uselseekwithSEEK_ENDas the origin, as it returns the new offset in the file, eg. ``` off_t fsize; fsize = lseek(fd, 0, SEEK_END); ```
I know I can get file size ofFILE *byfseek, but what I have is just a INT fd. How can I get file size in this case?
You can uselseekwithSEEK_ENDas the origin, as it returns the new offset in the file, eg. ``` off_t fsize; fsize = lseek(fd, 0, SEEK_END); ```
What the...argument means in the declarationstatic void info(const char *fmt,...)? It's part of anClibrary I recently started to use. Sorry if it's basicCstuff but I never saw that before and google is not so verbose about...!
It means variable arguments, which means the compiler will accept and compile calls to it with any arguments. Usually their types are indicated by values in preceeding arguments.
So I found Tk alikeGNOCLfor linux Gtk. I wonder if there is any alike Tk libraries using windows native buttons and other components for tcl? (the more its api looks like Tk the better.) Is there any su
Tk 8.5 has native look & feel support through theTiletheme engine, renamedTtk. If you're not using very exotic Tk features, it should be possible to replace Tk with Ttk in your application and get native looks, keyboard bindings, etc.
for example I can do ``` int *arr; arr = (int *)malloc(sizeof(int) * 1048575); ``` but I cannot do this without the program crashing: ``` int arr[1048575]; ``` why is this so?
Assumingarris a local variable, declaring it as an array uses memory from the (relatively limited) stack, whilemalloc()uses memory from the (comparatively limitless) heap.
I currently use c language to process the http event, and I need to do the SQL operation with mysql, then how to prevent the SQL injection, is there any c library for that,thank you?
SQL Injection Attacks and Some Tips on How to Prevent Them
This question already has an answer here:Closed12 years ago. Possible Duplicate:What does the : do in a struct declaration after a member I would like to ask why the:character was added in this struct: ``` typedef union A { struct { ubyte B:4; } } struct_a; ``` Thanks in advance;
The:4is putting a 4-bit limit on the variable. See Section 6.9 of Kernighan & Ritchie.
I saw this function in some code and I can't find documentation on google about it. Can someone explain what it does and are there any alternatives to this ? Thanks.
Seehttp://msdn.microsoft.com/en-us/library/tsbaswba%28VS.80%29.aspx: it is a generic name forsscanf_s. EDIT: which is conveniently documentedhere._stscanf_sis in TCHAR.H on Windows platforms. You can probably get away with usingsscanf_sorswscanf_s.
I'm working with a lexer that acceptsFILE*objects to read data from. I'd like to be able to pass it POSIX file descriptors (i.e. stuff you get fromopen, pipes, etc.). How can I turn a POSIX file descriptor into aFILE*?
On any POSIX-compliant system, you usefdopen().
I want to use a byte variableito execute a bit of code 256 times. The line below loops indefinitely, is there a tidy alternative that would work? ``` for (i = 0; i < 255; i++){ ``` Hopefully without using: a 16 bit variable, (or any extra bits at all)nested loopswhile(1)break;statements Thanks
``` i = 0; do { f(i); } while(i++!=255); ```
I am debugging some code and there is l_pid = 0 always for setting file locks.. It seems odd to me.. Is this correct?Documentation doesnt say about 0 zero value ..
l_pidis only meaningful when getting the lock status withF_GETLK; when setting a lock, if it succeeds then you know what pid owns it. :) (And the buffer is returned unmodified it it fails.)
I saw this function in some code and I can't find documentation on google about it. Can someone explain what it does and are there any alternatives to this ? Thanks.
Seehttp://msdn.microsoft.com/en-us/library/tsbaswba%28VS.80%29.aspx: it is a generic name forsscanf_s. EDIT: which is conveniently documentedhere._stscanf_sis in TCHAR.H on Windows platforms. You can probably get away with usingsscanf_sorswscanf_s.
I'm working with a lexer that acceptsFILE*objects to read data from. I'd like to be able to pass it POSIX file descriptors (i.e. stuff you get fromopen, pipes, etc.). How can I turn a POSIX file descriptor into aFILE*?
On any POSIX-compliant system, you usefdopen().
I want to use a byte variableito execute a bit of code 256 times. The line below loops indefinitely, is there a tidy alternative that would work? ``` for (i = 0; i < 255; i++){ ``` Hopefully without using: a 16 bit variable, (or any extra bits at all)nested loopswhile(1)break;statements Thanks
``` i = 0; do { f(i); } while(i++!=255); ```
I am debugging some code and there is l_pid = 0 always for setting file locks.. It seems odd to me.. Is this correct?Documentation doesnt say about 0 zero value ..
l_pidis only meaningful when getting the lock status withF_GETLK; when setting a lock, if it succeeds then you know what pid owns it. :) (And the buffer is returned unmodified it it fails.)
I found a C source in these files with.wextensions. It seems like a mix of TeX code and C Programming Language.Thisis an example of these sources. How can I compile? PS: Excuse me for the silly question but I didn't found any documentation
Use Knuth's CWEB, a literate-programming tool. You can download it fromhere.
Dcraw contains a following algorithm to process image colors:https://gist.github.com/1047302.Is it a formal (named) image processing algorithm? If not, what should I read to understand reasoning behind it?
It's not processing an image. It's generating a lookup table (curve[]) used to performgamma correction.
I am developing a C application using ncurses library in linux. my program cant distinguish between Alt and Esc keypresses. both return 27! can you help me how I can distinguish between the two? thank you
You need to incorporate a short delay after the^[in order to see if there are further characters incoming. If not, thenEschas been pressed.
Do these two statements compile equivalently: n % 2 == 0 and n & 1 == 0 ? if not, is one more efficient?
No, they do not always give the same result. The C standard allows for ones' complement implementations, in which case they will give a different result for negativen.
how can I get the user name that auth by pam_ldap in C/c++? I found "pam_get_user" API, but how can I get the pam_handle_t for this function? Thanks Dma
You get the handle by calling: ``` int pam_start(const char *service_name, const char *user, const struct pam_conv *pam_conversation, pam_handle_t **pamh); ``` pamh- is an output parameter in above api. Check more detailshere.
When declaring an enum as shown below, do all C compilers set the default values asx=0,y=1, andz=2on both Linux and Windows systems? ``` typedef enum { x, y, z } someName; ```
Yes. Unless you specify otherwise in the definition of the enumeration, the initial enumerator always has the value zero and the value of each subsequent enumerator is one greater than the previous enumerator.
I know it is a little bit off topic but I believe I can get the answer anyway here. What does "psz" stand for inpszBufferor the similar variable in C/C++ system library? I saw a lot of variables prefixed with "psz" and it looks like a pattern. Thanks!
This isHungarian notation.psznormally stands for "(p)ointer to (s)tring, (z)ero-terminated".
When declaring an enum as shown below, do all C compilers set the default values asx=0,y=1, andz=2on both Linux and Windows systems? ``` typedef enum { x, y, z } someName; ```
Yes. Unless you specify otherwise in the definition of the enumeration, the initial enumerator always has the value zero and the value of each subsequent enumerator is one greater than the previous enumerator.
I know it is a little bit off topic but I believe I can get the answer anyway here. What does "psz" stand for inpszBufferor the similar variable in C/C++ system library? I saw a lot of variables prefixed with "psz" and it looks like a pattern. Thanks!
This isHungarian notation.psznormally stands for "(p)ointer to (s)tring, (z)ero-terminated".
When declaring an enum as shown below, do all C compilers set the default values asx=0,y=1, andz=2on both Linux and Windows systems? ``` typedef enum { x, y, z } someName; ```
Yes. Unless you specify otherwise in the definition of the enumeration, the initial enumerator always has the value zero and the value of each subsequent enumerator is one greater than the previous enumerator.
I know it is a little bit off topic but I believe I can get the answer anyway here. What does "psz" stand for inpszBufferor the similar variable in C/C++ system library? I saw a lot of variables prefixed with "psz" and it looks like a pattern. Thanks!
This isHungarian notation.psznormally stands for "(p)ointer to (s)tring, (z)ero-terminated".
How can I remove the dot at the end of a line in C? This is my current code but it eliminates all dots, even in the middle of the word. ``` char *pc; pc = strtok(acData, " .\n"); ```
If your strings are of this format:word word word.Thenpc[strlen(pc) - 1]corresponds to\0andpc[strlen(pc) - 2]to the., so by doingpc[strlen(pc) - 2] = '\0';it will remove the.. If your strings contain\nthen you should dopc[strlen(pc) - 3] = '\0';.
For a 32 bit integer, how do I set say k low order bits in C?
Assuming you want to set theklowest bits of a 32-bit integerx, I believe this will work: ``` if( k > 0 ) { x |= (0xffffffffu >> (32-k)) } ```
How do I change the location where .obj, .exe files are generated in visual studio? I want these files to always be in a folder on the desktop
In the project properties, under Configuration Properties, you can set the Output directory and the intermediate directory.
In21.6.7.1,21represents the some segment,6represents some lane inside that segment and so on and so forth. The individual values need to be extracted. One way to represent this is string, any other way which is better and more convenient than string?
A structure with a four fields? An array of 4 elements, can also be an option.
I'm using C. How can I print the values of a member of an instance of a structure? Is it possible? At least is it possible in case of a structure declared as global variable (not a dynamically allocated one)?
``` set print objects on p structVar p *pointerToStructVar ``` Or, more explicitly: ``` p structVar.member p pointerToStructVar->member ```
Sorry about this basic question, but why0x11is17in decimal(print(%d, 0x11)=17? I search information about the way to convert from hex to dec, but it doesn't talk about this sort of numbers.
Just like "11" in base ten means "1 ten" and "1 one", "11" in base 16 (i.e. hex) means "1 sixteen" and "1 one" - or 17 in base 10.
In21.6.7.1,21represents the some segment,6represents some lane inside that segment and so on and so forth. The individual values need to be extracted. One way to represent this is string, any other way which is better and more convenient than string?
A structure with a four fields? An array of 4 elements, can also be an option.
I'm using C. How can I print the values of a member of an instance of a structure? Is it possible? At least is it possible in case of a structure declared as global variable (not a dynamically allocated one)?
``` set print objects on p structVar p *pointerToStructVar ``` Or, more explicitly: ``` p structVar.member p pointerToStructVar->member ```
Sorry about this basic question, but why0x11is17in decimal(print(%d, 0x11)=17? I search information about the way to convert from hex to dec, but it doesn't talk about this sort of numbers.
Just like "11" in base ten means "1 ten" and "1 one", "11" in base 16 (i.e. hex) means "1 sixteen" and "1 one" - or 17 in base 10.
I have.libfile compiled from C code. How I know if this self-contained static library or just an import lib and DLL will be needed at runtime? Is there somedumpbinoption I'm missing?
Use the lib command. If it's static, lib will show you a pile of .obj files inside. Not so if it's an implib. ``` lib /list foo.lib ``` will do it. Also see: https://learn.microsoft.com/en-us/cpp/build/reference/managing-a-library
This question already has answers here:Closed12 years ago. Possible Duplicate:In C arrays why is this true? a[5] == 5[a] ``` int a[5]={1,2,3,4,5}; int i=4; printf("%d",i[a]); ``` Why do a[i] and i[a] refer to same location in the array?
This is because array subscript iscommutative(it's an addition), the order can be swapped : ``` a[i] = *(a + i) i[a] = *(i + a) *(a + i) = *(i + a) a[i] = i[a] ```
I have installed mingW to use gcc, platform windows 7. I am trying to locate the standard C library libc.a in mingW folder. no luck.. is it stored in some other name?
MinGW does not build against glibc, it builds against msvcrt. As such, it uses libmsvcrtXX.a instead.
I am doing a GTK C program on Windows and I want to prevent the user from being able to select/highlight any rows in the tree view. Can anyone point me in the right direction?
The "gtk_tree_selection_set_select_function ()" seems to be exactly what you want. http://developer.gnome.org/gtk/2.24/GtkTreeSelection.html#gtk-tree-selection-set-select-function
I am wondering how to add the new line before closing the file. I have tried usingfputsandputsand frpints something likeputs("/n");etc but it doesnt work. Thanks & regards, SamPrat
a very simple way, no error checking: ``` FILE * file = fopen(fname, "a"); fwrite("\n", strlen("\n"), 1, file); fclose(file); ```
I am working on a project which involves stereo-vision. I am using c and openncv right now. I want to make a 3D plot of points based on their calculated position. Can someone tell how to do it in c or opencv? platform: XP, visualstudio 2005
You need a 3D rendering engine like OpenGL or DirectX. You can use any of them in VS2005 and WindowsXP.
was wondering if an Equivalent of PHP'sstripslashes()in C existed?
No, because this is not a problem that is usually encountered in C. If you want the same functionality then you will need to write it yourself, or find some library that provides it.
Hi I am trying to use C to parse xml, but all the examples I can find are using a file to get the xml, I have the xml already loaded into a variable and I want libxml2 to take the xml from there instead of a file.... but I can't figure out how! Any help would be appreciated thanks
Have a look atthis example:usingXmlReadMemory
I have an old piece of software that uses gtkembedmoz, and I need to update it to run on ubuntu lucid, which does not provide that library. What API replaces the functionality that it provides?
You should useWebkitGTKthese days for embedding a web browser into a GTK program.
Just want to know whether the casts in the example below are redundant. uint16_t basic_units = 4587U; uint8_t int_val = (uint8_t) (((uint16_t ) (basic_units * 5U)) / 1000U);
Theuint8_tcast is redundant. Theuint16_tcast may have the (un)intended consequence of truncating an intermediate value in the calculation ifbasic_units * 5Uwould overflow a normaluint16_tbefore being divided by 1000.
i wanted an UDisks script to list all the usb devices that are mounted on my system , which must have ability to detect LVM devices. Perl / C / Shell any is fine Many thanks. P.S: Hal is deprecated on my Gentoo and removed
loads of info about udisks herehttp://igurublog.wordpress.com/2011/01/26/a-custom-udisks-automounter/
I want to combine both the for loops into single for loop. How can i do that? I want to loop through a to z, and A to Z, like so: ``` char ch; for (ch = 'A' ; ch <= 'Z' ; ch++ ) { } for (ch = 'a' ; ch <= 'z' ; ch++ ) { } ``` but using a single loop.
``` for (char ch = 'A' ; ch <= 'z' ; ch == 'Z' ? ch = 'a' : ++ch ) { } ``` Should work -- though please, please, don't inflict this on your fellow developers.
i like to get float value with first two decimal value in C language. my input is ``` Float f; f=2.3678; ``` i like to get output like this ``` 2.36 ```
Include themath.hheader file and do this: ``` float f; f = 2.3678; f = floor(f * 100) / 100; // f = 2.36 ```