question
stringlengths
24
425
answer
stringlengths
5
405
This question already has answers here:What does "%3d" mean in a printf statement?(8 answers)Closed4 years ago. can someone explain what the 25 in front of d does in an printf command ? I have searched the web but don't find a good answer. e.g.: printf("%-30s %10lu %25d - %ud\n", "unsigned int", sizeof(unsigned int), 0, UINT_MAX); Thanks in advance.
%d indicates decimal value.25 total field width.
This question already has answers here:What does "%3d" mean in a printf statement?(8 answers)Closed4 years ago. can someone explain what the 25 in front of d does in an printf command ? I have searched the web but don't find a good answer. e.g.: printf("%-30s %10lu %25d - %ud\n", "unsigned int", sizeof(unsigned int), 0, UINT_MAX); Thanks in advance.
%d indicates decimal value.25 total field width.
I have a MIDI controller with several knobs. Is it possible to query state of all values, which these knobs have, when I connect to the device usingmidiInOpenfunction without physically moving each of them?
There is no standard MIDI message to inquire about the current state of a controller; messages are sent only when something changes. Unless your controller has a vendor-specific extension that does exactly what you want, this is not possible.
I want to print function names (imported, exported, normal/local functions) but not variable names and so on. SymEnumSymbolsExenumerates all symbols, but I only want functions. Also can not find how to distinguish functions and variables insidecallbackfunction. Is there a way to enumerate only functions?
SYMBOL_INFOpassed to your callback hasFlags, and there isSYMFLAG_FUNCTIONfor functions
I have an fmp4 file (using h264 and aac frame codes). When playing with VLC, only video has no audio, but the audio can be parsed with PotPlayer. The AAC format is ADTS.The screenshot of my fmp4 audio-related box is as follows
Mp4 should not have ADTS headers in the data. Just raw aac frames plus a configuration record in esds.
I have an fmp4 file (using h264 and aac frame codes). When playing with VLC, only video has no audio, but the audio can be parsed with PotPlayer. The AAC format is ADTS.The screenshot of my fmp4 audio-related box is as follows
Mp4 should not have ADTS headers in the data. Just raw aac frames plus a configuration record in esds.
I am writing a C program that does many comparisons and I was wondering if this actually saves memory. Any help appreciated
No, it does not. Using a tricky syntax to do something that there's a well-known syntax for is never the right answer. You should use x==a.
"Production compilers also exist for several other machines, including the IBM System/370, the Honeywell 6000, and the Interdata 8/32."
Compilers which are production-ready. Ie. It conforms to all requirements to be used in a production environment. It generates stable, executable software for the platform it is designed to. This is as opposed to an experimental compiler or an in-development compiler.
"Production compilers also exist for several other machines, including the IBM System/370, the Honeywell 6000, and the Interdata 8/32."
Compilers which are production-ready. Ie. It conforms to all requirements to be used in a production environment. It generates stable, executable software for the platform it is designed to. This is as opposed to an experimental compiler or an in-development compiler.
"Production compilers also exist for several other machines, including the IBM System/370, the Honeywell 6000, and the Interdata 8/32."
Compilers which are production-ready. Ie. It conforms to all requirements to be used in a production environment. It generates stable, executable software for the platform it is designed to. This is as opposed to an experimental compiler or an in-development compiler.
what does asterisk(*++argv) mean? ``` void main (int argc, char *argv[]) { while (--argc) { printf ("%s\n", *++argv); } } ```
hereargvis a pointer to a pointer ofchartype *argvpoints to the first argument string in the argv array, which is same asargv[0], similarly*(argv + 1)andargv[1]point to second argument string and so on.. Pointers in C: when to use the ampersand and the asterisk?
What is_ALPHA_macro? I found this macroin this code. What do you use this macro for? Please tell me this macro or its references.
I believe it is a macro that is#defined if the file is being compiled forDEC Alpha architecture. With Windows, of course, one must note that Alpha support was there for Windows NT (discontinued after NT 4.0; and pre-release Windows 2000 RC1) it means that in practice it is never#defined.
What is_ALPHA_macro? I found this macroin this code. What do you use this macro for? Please tell me this macro or its references.
I believe it is a macro that is#defined if the file is being compiled forDEC Alpha architecture. With Windows, of course, one must note that Alpha support was there for Windows NT (discontinued after NT 4.0; and pre-release Windows 2000 RC1) it means that in practice it is never#defined.
Is there function in a C library that iterates through an array and checks if two characters are next to each other? For example :array[30] = "example@.com"Is it possible to go through the array and check if '@' and '.' are next to each other?
Usestrstr: ``` if (strstr(array, "@.") || strstr(array, ".@")) /* the characters are touching */ ```
Is there function in a C library that iterates through an array and checks if two characters are next to each other? For example :array[30] = "example@.com"Is it possible to go through the array and check if '@' and '.' are next to each other?
Usestrstr: ``` if (strstr(array, "@.") || strstr(array, ".@")) /* the characters are touching */ ```
The question concerns implicit multiplication by the-operator. For example ``` float a = 10; float b; ``` b = -a;Is this valid? doesb = -10?
This isn't implicit multiplication, but use of the unary-operator. The code is valid, since the operator works on all arithmetic types, including floating point.
I am attempting to use a variable to store a conditional statement's result: ``` int age = 40; int validAge = age > 40; if (validAge) { /* ... */ } ``` Is the above code example allowed in C? If so, what type should I set these conditional variables?
This is valid. The expressionage > 40evaluates to either 0 or 1, so you can use any integer type (char,short,int,long, either signed or unsigned) to store it.
I am attempting to use a variable to store a conditional statement's result: ``` int age = 40; int validAge = age > 40; if (validAge) { /* ... */ } ``` Is the above code example allowed in C? If so, what type should I set these conditional variables?
This is valid. The expressionage > 40evaluates to either 0 or 1, so you can use any integer type (char,short,int,long, either signed or unsigned) to store it.
How can I show theprintfstatements inrpl-of0.cin the mote output window like the way we can see theprintfstatements inrpl-icmp6.c? I have triedDEBUG_PRINTandDEBUG_FULLbut to no avail.
replace#define DEBUG DEBUG_NONEwith#define DEBUG DEBUG_PRINT
Why does-fsanitize=undefinedthrow runtime error: left shift of 1 by 31 places cannot be represented in type 'int' on this code ``` uint32_t z; z = 1 << 31; ``` ?
Make the 1 unsigned: ``` uint32_t z; z = UINT32_C(1) << 31; ```
So, I'm trying to compile my C code using the command "gcc -o file file.c", but I get "error: libnet.h: No such file or directory" I included libnet.h (#include ) and I also installed libnet. I'm running CentOS 7.
yum install libnetonly installs the precompiled library. You need to install the headers usingyum install libnet-develbefore you can use it in your own software.
It's a long time since I did any coding of any sort. I'm trying to remember the name (in C) of an item you put at the beginning of your code that allows compilation to a constant for efficiency but can have its value adjusted before compilation if necessary. What is it called? (specifically the name in C and optionally the name in general) Thanks.
#definestatements allow you to define a constant at the beginning of your code.
So, I'm trying to compile my C code using the command "gcc -o file file.c", but I get "error: libnet.h: No such file or directory" I included libnet.h (#include ) and I also installed libnet. I'm running CentOS 7.
yum install libnetonly installs the precompiled library. You need to install the headers usingyum install libnet-develbefore you can use it in your own software.
It's a long time since I did any coding of any sort. I'm trying to remember the name (in C) of an item you put at the beginning of your code that allows compilation to a constant for efficiency but can have its value adjusted before compilation if necessary. What is it called? (specifically the name in C and optionally the name in general) Thanks.
#definestatements allow you to define a constant at the beginning of your code.
Is there a possibility to split large.afiles into multiple smaller ones? I'm currently having an issue with a.afile being multiple GiB large and GCC raises an error even with the flag-mcmodel=medium.
Use binutils tool "ar": ``` ar -x libbig.a ``` for extracting the objects from the archive and ``` ar -r libsmall.a obj1.o obj2.o obj3.o ``` for creating a new archive.
Is there a possibility to split large.afiles into multiple smaller ones? I'm currently having an issue with a.afile being multiple GiB large and GCC raises an error even with the flag-mcmodel=medium.
Use binutils tool "ar": ``` ar -x libbig.a ``` for extracting the objects from the archive and ``` ar -r libsmall.a obj1.o obj2.o obj3.o ``` for creating a new archive.
time_t t; printf("%f\n",time(&t)); it throws "Can not print float number"
You may try #include <stdlib.h> printf("%jd\n", (intmax_t) time(NULL));.
This is my code : ``` void render(char * world) {...} int main() { char world[HEIGHT * WIDTH]; render(&world); return 0; } ``` Tell me if I have given enough information! Thanks in Advance!
You just need to passworld. Passing&worldis passing the address ofworld, which is already achar *, so you're passing achar **.
This is my code : ``` void render(char * world) {...} int main() { char world[HEIGHT * WIDTH]; render(&world); return 0; } ``` Tell me if I have given enough information! Thanks in Advance!
You just need to passworld. Passing&worldis passing the address ofworld, which is already achar *, so you're passing achar **.
manpages of theprintfand online documentations often showprintf(3)when explaining the functionality ofprintf. What does the "3" denote?
3denotes the section whichprintfis a part of. Section3corresponds to: Library calls (functions within program libraries). You could also issueman <section number> <keyword>, eg.man 3 printfto look up a keyword in a specific section.man 1 printfwill show you theprintfshell command.
I compiled a program and get ``` format_io.c:3:6: error: cannot combine with previous 'void' declaration specifier void int int int ^ format_io.c:3:10: error: cannot combine with previous 'void' declaration specifier void int int int ^ ``` how readformat_io.c:3:6:,when check line 6, do no t find the void error.
filename:line:column Column 6 of line 3. And column 10 of line 3.
I'm not sure about how to get an inverse index , index%size it's ok to a straight ring index but what I need it's if tou are in 0 index get the last index as the previous of 0. ``` [0][1][2][3] // the previous index of 0 should be 3 ```
In the languageCthe remainder operator can be used as follows to get a true (positive) modulo result: ``` (index+n-1)%n ``` wherenis the length of your array.
I mean this | | not this %. Like let's say that I've got two integers x and y and and integer z. Now ``` z = x - y ``` Is there a way to express |z| so that if z is positive it stays positive and if z is negative it's turnt into its opposite? I don't mean to express it with an if, just a mathematical equation, symbol or something like that.
You want theabs()function, provided in themath.hheader. Example: ``` z = abs(x - y); ```
I found this question: What is the output ofprintf("%-x", 2048);? I know that the"%x"is outputting the hexadecimal format of the number, but I can' quite understand what the minus sign does here, since the output is the same for bothprintf("%-x", 2048);andprintf("%x", 2048);.
std::printf, std::fprintf, std::sprintf, std::snprintf: -: the result of the conversion is left-justified within the field (by default it is right-justified)
I found this question: What is the output ofprintf("%-x", 2048);? I know that the"%x"is outputting the hexadecimal format of the number, but I can' quite understand what the minus sign does here, since the output is the same for bothprintf("%-x", 2048);andprintf("%x", 2048);.
std::printf, std::fprintf, std::sprintf, std::snprintf: -: the result of the conversion is left-justified within the field (by default it is right-justified)
I came up on this question: I have the following instruction ``` float *f = (float*) malloc(5*sizeof(float)); ``` and a consequence of this is that ``` &f is of type float** ``` I don't understand why it's like this.
The type offisfloat*, i.e., a pointer to float. So&fis the address off, so its type is address to pointer of float, aka pointer to pointer of float, meaningfloat**.
I'm trying to pass a string to a function: ``` void PassString(unsigned char * value) { // ... } int main(void) { while(1) { PassString("TEST"); } } ``` I'm getting warning: (359) illegal conversion between pointer types.
The string literal being passed is of typechar []but the argument is given asunsigned char *. So change the type of the argument tochar[].
Let's say I have: file1.c ``` uint8_t array[] = {1, 2, 3}; ``` main.c ``` extern uint8_t array[]; ``` Does this create a copy of the variable array in main.c?
No, it tells the linker "there's a variable somewhere with this name, please fill in a reference to it whenever it's mentioned".
Is it possible to have a POSIX thread remain "alive" after executing the function given as an argument? As in reusing that thread for further work. For example, given a queue of functions to execute, is it possible to have a pthread execute several of them? The alternative would be creating a pthread for every task.
No. What you describe reminds me of athread pool, where a set of threads is waiting for work (your functions in this case) to execute.
I am creating a program that implements a tic-tac-toe game using a 2-D array with multiple functions. How would I create a function where it clears all 'x' and 'o' characters in each cell and have the cells reset it back to the underscore character '_'? An example along with your explanation would be much appreciated!
You can usememsetto reset the array to_as below. ``` char array[10][10]; memset(array, '_', sizeof(array)); ```
Is there any way to let CLion update the declaration in the .h file if I change the function definition in the .c file ? The copy and pasting is such a repetitive task..
It depends on changes I guess. I always useRefactor->Change Signatureto update function return type, name, arguments in both files (source and header).
I have no idea how to pass command like: ``` echo -e \"\E[1;3mHello!" ``` tosystem(), since I have to put it in quotation marks cause it'sconst char, any help?
Double quotes need to be escaped in strings, as do backslashes: ``` system("bash -c 'echo -e \"\\E[1;3mHello!\"'"); ```
Does thegcc 166 compilerfor theSiemens C167micro controller exist in open source ?, or can I find it?
According to the sitelinkI found thatGCC 166it is a compiler available for sale byRigel corp
Does thegcc 166 compilerfor theSiemens C167micro controller exist in open source ?, or can I find it?
According to the sitelinkI found thatGCC 166it is a compiler available for sale byRigel corp
This question already has answers here:struct declaration(2 answers)Closed4 years ago. I read such a snippet code of in5.2.  The indirection: ``` struct contact { int n1; float n2; char st[10]; } d1; ``` What's the meaning of using d1 here? is it a recommended practice to define such a struct?
That simply declare astruct contactvariable namedd1. That is not really readable and is not used generally.
I was given the task of writing a program that determines the maximum number of processes a user can have, just like the bash's "ulimit -u" built-in command butusing system calls and C. Any hint as to how achieve this?
Theulimitbuiltin is just an interface to thegetrlimitandsetrlimitfunctions. See thegetrlimit, setrlimit man page. In particular, you are interested in theRLIMIT_NPROCresource.
I see that theapr_pool_*interface exposes void apr_pool_tag (apr_pool_t *pool, const char *tag) which lets me tag a pool. That's all well and good, but how do I extract the tag from a pool at a later time? I can't find the "getter" for the above setter. How are these tags used?
Trunk (aka 2.0) has anapr_pool_get_tag(), but in released branches pool tagging is meant as a debugging aid. In other words, post-mortem analysis with a debugger.
I see that theapr_pool_*interface exposes void apr_pool_tag (apr_pool_t *pool, const char *tag) which lets me tag a pool. That's all well and good, but how do I extract the tag from a pool at a later time? I can't find the "getter" for the above setter. How are these tags used?
Trunk (aka 2.0) has anapr_pool_get_tag(), but in released branches pool tagging is meant as a debugging aid. In other words, post-mortem analysis with a debugger.
I see that theapr_pool_*interface exposes void apr_pool_tag (apr_pool_t *pool, const char *tag) which lets me tag a pool. That's all well and good, but how do I extract the tag from a pool at a later time? I can't find the "getter" for the above setter. How are these tags used?
Trunk (aka 2.0) has anapr_pool_get_tag(), but in released branches pool tagging is meant as a debugging aid. In other words, post-mortem analysis with a debugger.
I have a UnsafeMutablePointer pointing at a C string, I want to convert the bytes at this pointer to a Swift String, the data is a C string, so UTF8. Is it possible to iterate byte by byte until NULL? Or some easier way?
CChar is an alias for Int8, so you can useCChar-based methodshere. ``` let str = String(cString: pointer) ```
Let's say I have two variables. ``` int a = -10; int b = 10; ``` How can I return 0 if they have different sign or 1 if they have same signs ? Again without if statements
Like this? ``` return ((a >= 0 && b >= 0) || (a < 0 && b < 0)); ```
For example: ``` void *p1 = someStringPointer; void *p2 = p1; ``` Although these are two unique pointers, given that they both point to the same value, are they still different memory objects?
If you print the address ofp1andp2 ``` printf("%p\n", (void *) &p1); printf("%p\n", (void *) &p2); ``` They have different addresses, so yes they are different memory objects.
How can I create an array such that I could access the elementsa[1000000],a[1]anda[2]and not even using the size of 1000000? If possible please provide the answer inC++.
Usestd::unordered_map<>. ``` enum { N = 9 }; int arr[N] = { 0 }; std::unordered_map<int, int> m; for (int i = 0; i < N; i++) { ++m[arr[i]]; } ```
In this code the person has to enter y if wishes to continue, but why does it ask him the question two times when he enters y. ``` char c = 'y'; while(c!='n'){ printf("Do you wish to continue: (y or n):"); c = getchar(); } ``` Here is the console
why does it ask him the question two times when he enters y The enter key the user hits is taken as another character (a new-line:\n) as well.
In this code the person has to enter y if wishes to continue, but why does it ask him the question two times when he enters y. ``` char c = 'y'; while(c!='n'){ printf("Do you wish to continue: (y or n):"); c = getchar(); } ``` Here is the console
why does it ask him the question two times when he enters y The enter key the user hits is taken as another character (a new-line:\n) as well.
I am following instructions to write a program of characters counting: ``` #include <stdio.h> main() { double nc; for (nc=0; getchar() != EOF; ++nc); printf("%.0f\n", nc); } ``` After it was compiled and run, ``` $ ./a.out ff fdg fd fdr ``` It did not print the counting.What's the problem with my code?
I'm pretty sure you never enterEOF. UseControl+Zon Windows orControl+Don UNIX/Linux/OSX to getEOF.
I am struggling to understand if there is any overflow with the following equation using 8 bit signed integers.0b00000000 - 0b10000000
This question is taggedc, and in C, all arithmetic in types lower-rank thanintgets promoted toint, andinthas at least 16-bit range, so(signed char)0-((signed char)-128)is just 128.
I was getting wrong values fromlog(), so I wrote this program just for testing: ``` #include <math.h> #include <stdio.h> void main() { printf ("%1f", log(10)); } ``` This should print "1", but I get "2.302585" Why is this and how can I fix it?
Thelogfunction is for thenaturallogarithm with basee. It seems you wantlog10instead.
``` struct Node *prevX = NULL, *currX = *head_ref; while (currX && currX->data != x) { prevX = currX; currX = currX->next; } ``` Why was currX placed here? How can it affect the outcome?
while (currX)tests the truthiness ofcurrX. It's effectively short forwhile (0!=currX).
``` struct Node *prevX = NULL, *currX = *head_ref; while (currX && currX->data != x) { prevX = currX; currX = currX->next; } ``` Why was currX placed here? How can it affect the outcome?
while (currX)tests the truthiness ofcurrX. It's effectively short forwhile (0!=currX).
I have a rather odd situation where I will have multiple interfaces connected to the same network. When I receive a broadcast or multicast message, I would like to know what interface it came from. It there a way to do that in C or ideally Python? Thanks!
The most obvious one would be to bind several sockets, each toone interface only- do not listen to0.0.0.0.
What is the intention to set handle to an object as pointer-to pointer but not pointer? Like following code: ``` FT_Library library; FT_Error error = FT_Init_FreeType( &library ); ``` where ``` typedef struct FT_LibraryRec_ *FT_Library ``` so&libraryis aFT_LIBraryRec_handle of typeFT_LIBraryRec_**
It's a way toemulatepass by reference in C, which otherwise only have pass by value.
What is the intention to set handle to an object as pointer-to pointer but not pointer? Like following code: ``` FT_Library library; FT_Error error = FT_Init_FreeType( &library ); ``` where ``` typedef struct FT_LibraryRec_ *FT_Library ``` so&libraryis aFT_LIBraryRec_handle of typeFT_LIBraryRec_**
It's a way toemulatepass by reference in C, which otherwise only have pass by value.
If there is a broken VHD chain (for example the parent VHD was modified, that's why the child no longer mounts), there's a way to fix it by using Hyper-V "Reconnect" feature. How do I do the same programmatically?
I think you wantAttachVirtualDisk, but I'm not sure if that's what you are after with regards to VHD chains.
If there is a broken VHD chain (for example the parent VHD was modified, that's why the child no longer mounts), there's a way to fix it by using Hyper-V "Reconnect" feature. How do I do the same programmatically?
I think you wantAttachVirtualDisk, but I'm not sure if that's what you are after with regards to VHD chains.
``` int pop(STA* stack) { if (!isEmpty(stack)) return stack->array[stack->top--] ; return '$'; } ``` What is the useage of the (return'$') in this function? What kind of value will it return?
It seems like it's just default return value in case stack is empty (which should not really happen, precondition of callingpop()should be for stack not to be empty. ) It will return 36 ( code of$)
I noticed thatprintf()has specifiers%Fand%f. What are the differences? The link above says%Fwill give "Decimal floating point, uppercase". I fail to see what an uppercase floating point is. Thanks!
Per the C 2018 standard, clause 7.21.6.1, paragraph 8: The F conversion specifier produces INF, INFINITY, or NAN instead of inf, infinity, or nan, respectively.
I have a portion of the code as: ``` __weak void TimingDelay_Decrement(void) { } ``` and it keeps throwing up the captioned error. I checked the web and couldn't find relevant content for the__weakcase. Any help is appreciated.
Because it is ARM Cortex gcc toolchain so the__weakis a definition of__attribute__((weak)). The easiest way to add is to amend thegcccommand line arguments:-D__weak=__attribute__((weak))
If I have multiple if-statements nested inside each other which are all in a for-loop, will a break statement on the inner-most if-statement break out of the for-loop or just into the next if statement?
It will break the loop (the inner most loop that the if contains in) no matter how many if statments are nested inside. Abreakbreaks from a loop and not from if statement.
This program gives output as 4 3 2 1. Why does it stop at 1 when no condition is given for i? Do main(10) and main(i) differ? ``` #include <stdio.h> int main() { static int i = 5; if (--i){ printf("%d ", i); main(i); } } ```
You actually have a condition: if (--i)is equivalent toif(--i != 0)
I typed this program on code blocks but it is showing error on int main line Here's the program ``` #include <stdio.h> int main() { printf("Hello"); return 0; } ``` The message return is " multiple definition of main"
The sample code is correct. It might be an IDE configuration error. Usegccto compile your code on Linux and on Windows you can installMinGWand execute from a command window.
I am a beginner to ffmpeg and libavcodec in c programming on a linux machine. I want to know the difference between these API's.
av_register_allregisters absolutely everything - i.e. muxers, demuxers and protocols + it calls toavcodec_register_all.avcodec_register_allonly registers codecs. Bare codecs are seldom useful as such.
``` main() { char a1='='; char a2='='; printf("%d",a1+a2); } ``` Code is as above , it simply perform '='+'=' and printing the value 122.(why??)..
Because ASCII value of'='is61 ASCII Values
the following short code snippet results in a invalid initializer error, and as a beginner in C, I do not understand why. ``` unsigned char MES[] = { 0x00, .... }; unsigned char *in[] = &MES; ``` Is this not the correct way to do it?
&MESis a pointer to an array ofunsigned char. inis an array of pointers tounsigned char. Try instead : ``` unsigned char (*in)[] = &MES; ``` which makesinalso a pointer to an array ofunsigned char.
All I can find on this topic is mentions ofFSMoveObjectToTrashSyncfunction, which is nowdeprecated and no alternative is listed for it. How to do it from C or Objective-C code?
Use NSFileManager: https://developer.apple.com/documentation/foundation/nsfilemanager trashItemAtURL:resultingItemURL:error: Moves an item to the trash.
This question already has answers here:How to check the value of errno?(3 answers)Closed5 years ago. I'm using syscallstat, it returns 0/-1. When -1 is returned it means, error occurred and errno is set as it should be (source:man 2 stat). But I want to access errno and print it, how to do that?
You can get it fromerrno. Also you can print the error usingstrerror
i'm recording with VUG and receive this error when click a button to acces to another page. here is my configuration: If someone know how to solve it, thanks in advance.
go under recording options and set a new connection. Any server, all Ports (value 0) and go further with the settings (direct/proxy etc.). If you are not sure which settings you should use just try and edit them as long as the record is empy
i'm recording with VUG and receive this error when click a button to acces to another page. here is my configuration: If someone know how to solve it, thanks in advance.
go under recording options and set a new connection. Any server, all Ports (value 0) and go further with the settings (direct/proxy etc.). If you are not sure which settings you should use just try and edit them as long as the record is empy
What I'm trying to do would look like this in Python (wherenis float/double): ``` def check_int(n): if not isinstance(n, numbers.Integral): raise TypeError() ``` Since C/C++ are typestrong, what kind of cast-and-compare magic would be the best for this purpose? I'd preferably want to know how it's done in C.
Usefloor ``` #include <cmath> if (floor(n) == n) // n is an integer (mathematically speaking) ```
Is it possible to create a window without it showing up on taskbar in X11 using c?
That depends on GUI toolkit you are using. For example, GTK+ providesgdk_window_set_skip_taskbar_hintfunction. If you don't use any GUI toolkit and directly interface X11, you need to add_NET_WM_STATE_SKIP_TASKBARatom to_NET_WM_STATEproperty.
Is it possible to create a window without it showing up on taskbar in X11 using c?
That depends on GUI toolkit you are using. For example, GTK+ providesgdk_window_set_skip_taskbar_hintfunction. If you don't use any GUI toolkit and directly interface X11, you need to add_NET_WM_STATE_SKIP_TASKBARatom to_NET_WM_STATEproperty.
``` const int rxBytes = uart_read_bytes(UART_NUM_0, data, RX_BUF_SIZE, 10 / portTICK_RATE_MS); ```
To flush input data you can read from the uart repeatedly with a timeout of 0 until zero bytes are returned.
void TraverseList(const List *l , void (*Visit)(ListEntry)) { // } I confused about the above function call within the argument of a function,how it is working?
Visitis a function pointer parameter passed to theTraverseListfunction. It should point to a function with the format ``` void func (ListEntry); ``` Likely,TraverseListwill call the passed function for every item in the list.
void TraverseList(const List *l , void (*Visit)(ListEntry)) { // } I confused about the above function call within the argument of a function,how it is working?
Visitis a function pointer parameter passed to theTraverseListfunction. It should point to a function with the format ``` void func (ListEntry); ``` Likely,TraverseListwill call the passed function for every item in the list.
When we have : ``` struct node { char... int.... struct node *.... } typedef struct node Node; ``` and then we have a function like this: ``` int function(Node f){...} ``` What is thisf?
fis an input argument of the typeNode. The typeNodeis synonym of the typestruct node.
``` #include <stdio.h> int main() { int i=0; while(i++,i<=8); printf("%d\n",i); return 0; } ``` Why is the increment ofidone after the comparison in each test case?
i <= 8succeeds for the last time wheni = 8. In the last iteration,i++is executed, theni <= 8fails becausei = 9. Note that the,is asequence point, soi++is absolutely guaranteed to be executed beforei <= 8.Not so for similar constructs.
``` #include <stdio.h> int main() { int i=0; while(i++,i<=8); printf("%d\n",i); return 0; } ``` Why is the increment ofidone after the comparison in each test case?
i <= 8succeeds for the last time wheni = 8. In the last iteration,i++is executed, theni <= 8fails becausei = 9. Note that the,is asequence point, soi++is absolutely guaranteed to be executed beforei <= 8.Not so for similar constructs.
I have this code ``` if(orden[i]==1) for(i=0; i<ARRAY_SIZE; i++) if(v[i]<v[i+k]) printf("print once "); ``` How can I make it so that it prints the line only once, if the condition inside the for loop is satisfied?
Use thebreakcommand to exit theforloop. ``` if(orden[i]==1) for(i=0; i<ARRAY_SIZE; i++) if(v[i]<v[i+k]) { printf("print once "); break; } ```
int main(int argc, char* argv[]) In this code argv[] is a string not array so how can i use as a array to perform sum operation?
You can do it like this ``` #include <stdio.h> #include <stdlib.h> int main(int argc, char const *argv[]) { int sum = 0; int i = 1; for(;i<argc;++i) sum += atoi(argv[i]); printf("%d\n",sum); return 0; } ``` And the result: ``` $ gcc test.c && ./a.out 1 2 3 4 10 ```
int main(int argc, char* argv[]) In this code argv[] is a string not array so how can i use as a array to perform sum operation?
You can do it like this ``` #include <stdio.h> #include <stdlib.h> int main(int argc, char const *argv[]) { int sum = 0; int i = 1; for(;i<argc;++i) sum += atoi(argv[i]); printf("%d\n",sum); return 0; } ``` And the result: ``` $ gcc test.c && ./a.out 1 2 3 4 10 ```
I wrote an ntrip client in C using sockets(http://read.pudn.com/downloads116/sourcecode/unix_linux/493018/NtripLinuxClient.c__.htm), Receiving the reqest works fine, but after some time the server stops sending correction data because I do not now how to send nmea updates to the server. Does anyone know how that would work? thanks in advance
You just need to send your_nmea + '\r\n' regularly and that should work.
I wrote an ntrip client in C using sockets(http://read.pudn.com/downloads116/sourcecode/unix_linux/493018/NtripLinuxClient.c__.htm), Receiving the reqest works fine, but after some time the server stops sending correction data because I do not now how to send nmea updates to the server. Does anyone know how that would work? thanks in advance
You just need to send your_nmea + '\r\n' regularly and that should work.
``` a|b=c ``` knowingaandc, how to calculateb For example: ``` 0011 | b = 0111 ``` Knowinga = 0011andc = 0111, how to figure outbto be0101
There will be more than one correct answer. For simplicity consider the trivial example:1|0 = 1i.e. a=1, b=0 and c=1. In this case, b can also be 1. So given that the bit inais 1, we won't be able to know for sure whether the bit inbis 0 or 1.
I'm trying to do math calculations that they require more than 100 decimals of precision. C data types cannot go beyond 16 bytes (long double), so I cannot compute more than ~17 decimals. Is there a way to create a variable in C that can get more precision?
Realistically you need an arbitrary-precision arithmetic library, seeWikipediafor some options. I personally have foundGNU MPFRto be fairly reliable, though I have also heard good things aboutArb.
Given a preprocessor macro like ``` #define DECLARE(NAME) \ int NAME; \ int NAME_2 ``` Name_2denotes a new identifier. Is it possible to expandName, so that ``` DECLARE(x); ``` becomes ``` int x; int x_2; ```
You can use##glue: ``` #define DECLARE(NAME) \ int NAME; \ int NAME##_2 ```
Given a preprocessor macro like ``` #define DECLARE(NAME) \ int NAME; \ int NAME_2 ``` Name_2denotes a new identifier. Is it possible to expandName, so that ``` DECLARE(x); ``` becomes ``` int x; int x_2; ```
You can use##glue: ``` #define DECLARE(NAME) \ int NAME; \ int NAME##_2 ```
I'm wondering if someone know effective approach to calculate bits in specified position along array?
Assuming that OP wants to count active bits ``` size_t countbits(uint8_t *array, int pos, size_t size) { uint8_t mask = 1 << pos; uint32_t result = 0; while(size--) { result += *array++ & mask; } return result >> pos; } ```
I'm wondering if someone know effective approach to calculate bits in specified position along array?
Assuming that OP wants to count active bits ``` size_t countbits(uint8_t *array, int pos, size_t size) { uint8_t mask = 1 << pos; uint32_t result = 0; while(size--) { result += *array++ & mask; } return result >> pos; } ```
I am making calculator for physics, but when I was coding the focal length equation I needed to find the reciprocal of the fraction found for the focal length.
``` double eqn_reciprocal= pow(eqn,-1); ``` this would do the trick
PVS-Studio gave me a warning about this : ``` char c; sscanf(line, "%d", &c); ``` I changed %d to %c but this created a bug because "c" now contains the ASCII value of the number and not the decimal one, so I went back to "%d". So what's the correct specifier to ? is there another solution ?
cis achar. You asked to scan anint. PVS-Studio did right in warning you. Change the type ofctointand scan for a%d.