question
stringlengths
24
425
answer
stringlengths
5
405
With C igraph we can create a graph from an adjacency list withigraph_adjlist. It there a way to create a graph from an incidence list ?
Unfortunately no such functionality is implemented. Feel free to open an issue athttps://github.org/igraph/igraphto suggest such a feature. Alternatively, if you want to discuss it, theigraphproject recently opened a new forum to facilitate discussions, seehttps://igraph.discourse.group.
With C igraph we can create a graph from an adjacency list withigraph_adjlist. It there a way to create a graph from an incidence list ?
Unfortunately no such functionality is implemented. Feel free to open an issue athttps://github.org/igraph/igraphto suggest such a feature. Alternatively, if you want to discuss it, theigraphproject recently opened a new forum to facilitate discussions, seehttps://igraph.discourse.group.
Is there any way to get freetype man pages? I can't find them and have to use the documentation on the web. The problem is when I don't have internet access.
Freetype doesn't provide man pages. Only html documentation. You can download it fromhere(see the archives that have "-doc" in their name).
What is a difference between((int) a)and(int(a))? Is the second expression valid in pure "С" (not "C" under "C++")?
There's no difference between them in C++. However, C supports only the first cast operation. See this example fromtutorial: ``` double x = 10.3; int y; y = (int) x; // c-like cast notation y = int (x); // functional notation ```
This question already has answers here:Using true and false in C(15 answers)Closed3 years ago. I thought that C interpretedtrueas1but now I'm having doubts. Full code (compiled with GCC 5.1): ``` if(true && true) // Error: 'true' undeclared (first use in this function) { } ``` Why does this happen?
trueis not a keyword in C like it is in C++. To access it you'll have to#include <stdbool.h>.
``` int ch; scanf("%c", &ch); //Read a character (%c) printf("You entered char %c %d\n", ch, ch); return 0; ``` expected output: You entered char A 65Actual output: You entered char A 32577
chis of type int andscanf("%c", &ch)copies abytein to address location pointed by&ch.MachineEndiannessdecides where thecharvalue from iostream stored. ifchon stack garbage values present in remaining bytes ofch
I'm trying to access the whole array from a struct in a function, to compare two elements for no duplication. However, I am receiving anexpected expression errorinqueue.id[]. ``` int count = sizeof(queue.id[]) / sizeof(queue.id[0]); ```
``` int count = sizeof(queue.id[]) / sizeof(queue.id[0]); ``` should be ``` int count = sizeof(queue.id) / sizeof(queue.id[0]); ```
I have twouint64variablesvar_1andvar_2and I want to set the bits ofvar_1according to the low-order6bits ofvar_2. How can I do this in C language?
Like so: ``` uint64_t mask = 0x3F; var_1 &= (~mask); var_1 |= (var_2 & mask); ```
FILE *fopen(const char *filename, const char *mode); I saw that some people only put the name of the file inside the "filename" part, some others put the entire path example FILE *fopen("mytext.txt", r);FILE *fopen("/myfolder/mytext.txt", r); which is the correct one?
If the file is in current directory when you run the program - no. If it's not - yes, you will need to specify the path (absolute or relative to current directory)
I have twouint64variablesvar_1andvar_2and I want to set the bits ofvar_1according to the low-order6bits ofvar_2. How can I do this in C language?
Like so: ``` uint64_t mask = 0x3F; var_1 &= (~mask); var_1 |= (var_2 & mask); ```
Is there any other way of passing user's parameters into a program other than through ./program argument1 argument2 whereargument1andargument2will be passed on tomain'sargv[]?
Your application could read the values from the standard input, a configuation file or even environnent variables.
I'm using theVIPS libraryfor manipulating images and adding text to them. I want to know how to add spacing to characters in text? The following image is an example of what I'm talking about.
You can usepango markup. For example: ``` vips text x.png '<span letter_spacing="10000">Hello!</span>' --dpi 300 ``` To make:
Is there any other way of passing user's parameters into a program other than through ./program argument1 argument2 whereargument1andargument2will be passed on tomain'sargv[]?
Your application could read the values from the standard input, a configuation file or even environnent variables.
I'm currently developing a piece of software on a Raspberry Pi. Because I have to control motors very precisely i developed a C script, that does that for me. My current problem is, that I didn't found any solid method to transfer a list of signed floats from a Python3 Script to a C script. It is really important, that the method is fast.
You could use a socket to send data from one script to the another.
I'm currently developing a piece of software on a Raspberry Pi. Because I have to control motors very precisely i developed a C script, that does that for me. My current problem is, that I didn't found any solid method to transfer a list of signed floats from a Python3 Script to a C script. It is really important, that the method is fast.
You could use a socket to send data from one script to the another.
I would like to do something like setting a macro name that activates portions of my code.... g++ -DVERBOSE=1 main.cc during the Bazel build command: bazel build //myproj:main Is it possible?
bazel build //myproj:main --cxxopt=-DVERBOSE=1 Or, use thecoptsattribute incc_*targets. https://docs.bazel.build/versions/master/user-manual.html#flag--cxxopt
Is the codeint const*const pointer1=&constantVariable;legal? If it isn't, what is the correct way of specifying it?
It's OK! Inint const*const pointer1=&constantVariable, the firstconstindicates that you couldn't change the value by *pointer1; the secondconstindicates the value of pointer itself(an address) couldn't be changed too. Actually pointer1 can point to a constant integer, even a normal variable.But it can't be set twice.
Self explanatory question. Can we get multiple UDP packets in one socket recv call when using Multicast?
When usingrecvfromorrecvon a UDP socket, you will only ever receive one complete packet at a time. This applies to both unicast and multicast packets.
I triedlocate kmalloc_sizes.hbut didn't find the file. And I usedapt-fileto search but couldn't find the package. How can I get this header file?
The file you're looking for is actually calledkmalloc_sizes.h. You can get it by installing the Linux kernel headers: ``` sudo apt-get install linux-headers-$(uname -r) ``` Ref:https://askubuntu.com/questions/75709/how-do-i-install-kernel-header-files
Is there any piece of code I can write or any other way to check which version of the C language my compiler is compiling? I was wondering if there was a way for me to see if the compiler in question is C89, C99, C11, C18 etc. Perhaps utilizing__STDC_VERSION__.
You can look at the__STDC_VERSION__macro, which hast the format YYYYMM and from that deduce whether you run C89, C99, C11 or C18. See alsoWhat is the __STDC_VERSION__ value for C11?
I want to code a matrix calculator, and for that I need to ask the user for it's size,but when I'm declaring a 2d array it won't let me put a variable as a size, so what can I do? ``` int main() { int n; print_enter_matrix_size(); scanf("%d", &n); int matrix[n][n]; return 0; } ```
You can use dynamics arrays. For that you can use malloc to declare the size you want, Try this:allocate matrix in C
I have a really simple question: ``` const char *y = "string_test"; x = &y; ``` What type is x ? Thanks in advance for your answers !
Assuming you had a typo in your question, and the code is: ``` const char *y = "string_test"; x = &y; ``` x shall be defined as: ``` const char** x; // x is a pointer(Address of) a pointer to a constant char/string ```
I have a really simple question: ``` const char *y = "string_test"; x = &y; ``` What type is x ? Thanks in advance for your answers !
Assuming you had a typo in your question, and the code is: ``` const char *y = "string_test"; x = &y; ``` x shall be defined as: ``` const char** x; // x is a pointer(Address of) a pointer to a constant char/string ```
I am new to C. I just want to know why initializing the array of int with int is working and why initializing an array of char with char is not working. Oram I wrong thinking that "1" is a char? ``` #include <stdio.h> int main() { int incoming_message_test[2] = {1, 2}; // why does this work? char incoming_message[2] = {"1", "2"}; // why does this not work? return 0; } ```
You must change"1", "2"with'1', '2'
I don't seem to understand what's happening here ``` #include <stdio.h> int var = 5; int main(){ int var = var; printf("%d",var); return 0; } ``` Why does this program print a garbage value when the value of var is assigned to be 5?
the local var has priority on the global var. So the compiler translate it as (local) var = (local) var
I don't seem to understand what's happening here ``` #include <stdio.h> int var = 5; int main(){ int var = var; printf("%d",var); return 0; } ``` Why does this program print a garbage value when the value of var is assigned to be 5?
the local var has priority on the global var. So the compiler translate it as (local) var = (local) var
I am trying to find "python.exe" in szExeFile after aProcess32NextWcall. I tried doing a ``` if(strcmp(lppe->szExeFile,"python.exe") == 0){ //do stuff } ``` but the check always fails despite the process running. I have also tried using strncmp but it does not change anything. What am I doing wrong?
Process32NextW()seems to usePROCESSENTRY32Wstruct with wide character strings. Trywcscmp()instead ofstrcmp().
I am trying to find "python.exe" in szExeFile after aProcess32NextWcall. I tried doing a ``` if(strcmp(lppe->szExeFile,"python.exe") == 0){ //do stuff } ``` but the check always fails despite the process running. I have also tried using strncmp but it does not change anything. What am I doing wrong?
Process32NextW()seems to usePROCESSENTRY32Wstruct with wide character strings. Trywcscmp()instead ofstrcmp().
I'm trying tocompare a llvm Type and a Type*. I'm using the LLVM C APIs. Is there any possible method to do this? I haveType*because I did LLVMTypeOf api to get the type from an LLVM Value. So if I can get theType from a Value, it would also fix the issue.
Types are unique in LLVM world, so you could compare their addresses.
I'm trying tocompare a llvm Type and a Type*. I'm using the LLVM C APIs. Is there any possible method to do this? I haveType*because I did LLVMTypeOf api to get the type from an LLVM Value. So if I can get theType from a Value, it would also fix the issue.
Types are unique in LLVM world, so you could compare their addresses.
Is there a way to calculate the maximum value representable byunsigned intwithout usinglimits.h(so noUINT_MAX) or without using ``` unsigned int z = 0; z = z - 1; ```
The simplest way to do this is to simply assign -1 to anunsigned int. You could also assign~0uto it. If that's not acceptable, while inefficient, you could do something like this: ``` unsigned int i = 0; while (i+1 > 0) i++; printf("i=%u\n", i); ```
I have a file where I have saved C float arrays as binary data. Is it possible to load this binary data into a Python list now?
It's possible to do that using Numpy.memmap. Something like this: ``` import numpy as np arr = np.memmap("filename", dtype="int32", mode="r") ``` Replace "filename" with the path to your array file and "int32" with the type you used in your C array.
I have a file where I have saved C float arrays as binary data. Is it possible to load this binary data into a Python list now?
It's possible to do that using Numpy.memmap. Something like this: ``` import numpy as np arr = np.memmap("filename", dtype="int32", mode="r") ``` Replace "filename" with the path to your array file and "int32" with the type you used in your C array.
``` int x = 0x76543210; char *c = (char*) &x; Big endian format: ------------------ Byte address | 0x01 | 0x02 | 0x03 | 0x04 | +++++++++++++++++++++++++++++ Byte content | 0x76 | 0x54 | 0x32 | 0x10 | ``` why does the byte address ox01 stores only 0x76 not 0x765?
A byte is 8 bits, and in hex that goes from 0x00 --> 0xFF (0 -> 255). 0x765 - which is hex - cannot possibly fit in 8 bits.
Let's say x=29 and y=13. What does this line of code actually do: ``` x%=y-3; ``` I just don't really know what does this mean?
Modulo operator gives you remainder from division. a % bis the remainder of division a by b x %= y - 3is equal tox = x % (y - 3)and gives you remainder from division x by (y - 3) expression.
I saw this code: ``` char *str; // Some code if (! str || ! *str) return str; ``` Why need to check! *str? Isn'tif (! str)enough?
It depend on what you want to check: The!strcheck is str is NULL.The!*strchecks that the first char instris NUL byte ('\0') Combined, they will return 's' if s is NULL, or s point to a NUL char
I saw this code: ``` char *str; // Some code if (! str || ! *str) return str; ``` Why need to check! *str? Isn'tif (! str)enough?
It depend on what you want to check: The!strcheck is str is NULL.The!*strchecks that the first char instris NUL byte ('\0') Combined, they will return 's' if s is NULL, or s point to a NUL char
I have 2 files:stack.handstack.c. Both of them have a undefined typeelem_type. So my question is:Can I leave them undefined until I include the stack.h and then give it a definition depended on the need of the calling file ?
You cannot leave undefined type in stack.c in C because when a compiler tries to compile stack.c it won't be able to determine the type. In C++ this is feasible via template.
How do we add new line to output buffer using printf in C? Like in c++ we use endl, what do we use in C? ``` cout<<endl; ```
You can write like this printf("whatever message you want \n") "\n" added at the end output a new line in buffer.
Let's say I have the following piece of code: ``` void foo(){ static int bar = 0; bar++; } ``` Does two successive calls to this function reset the value of the variable?
Initialization occurs when an object is created. For static objects, their lifetimes start when program execution starts. They are not reinitialized or reassigned when execution reaches the statements that define them.
How should I read each of these definitions ? const char *arguments[]char *const arguments[] I saw examples ofexecl()code using the first form but could not make it work under Linux and had to use the second form ?
const char *arguments[] argumentsis an array of unknown size of pointers toconstqualifiedchar. char *const arguments[] argumentsis an array of unknown size ofconstqualified pointers tochar.
they used to ship sources for the C runtime in previous versions of VS. Would someone perhaps know what would be the default location in VS2017? Do they still ship the code with it?
Ah.. found it in Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\crt I hope the refactored code is as beautiful as the path is long.
``` #include <stdio.h> int main(){ int a[1] = {1}; int b = 6; printf("%d\n", a[-1]); printf("%d\n", b); //printf("%d\n", (a-1 == &b)); return 0; } ``` I wrote the above code and found out it didn't work properly when using gcc or mingw to compile it, but when I uncommented 8th line, everything is just fine. Could anyone explain the code for me?
Thea[-1]is undefined memory space.
This question already has answers here:Multiplication and division: weird output in c(3 answers)Closed4 years ago. I am using c preprocessor directive. I want to know how does this program work? ``` #define PRODUCT(x) (x*x) main() { int i=3,j; j=PRODUCT(i+1); printf("\n%d",j); } ``` The output is ``` 7 ```
Why do I get 7 withPRODUCT(i+1)? because3+1*3+1==3+3+1 Try#define PRODUCT(x) ((x) * (x))
I'm looking for an example of eBPF to write a seccomp filter, but I can't find none. Could someone tell me if is possible to use eBPF to write seccomp filter?
Seccomp does not work with eBPF at the moment (only cBPF). There wasa discussionnot long ago on that topic on the Linux networking mailing list. The eBPF maintainer is against adding eBPF support to seccomp.
I'm looking to break up binary into blocks or 8 digits. Is there a way to do the following in C without doing a second print line? ``` printf("%d%c", number>>(i-1) & 1, (i%8==0) ? ' ' : ''); ``` Or is it not possible to do the "empty char" and I should add a second line to check for that?
There's no such thing as an empty char. You can use%swith strings. ``` printf("%d%s", number>>(i-1) & 1, (i%8==0) ? " " : ""); ```
Is it possible to execute C code in a C program? For instance when reading input from the user.
There's nothing built in to do this. This simplest thing to do is save the given code to a separate file, invoke GCC as a separate process to compile the code, then run the compiled code in a new process.
``` #include <stdio.h> int main() { int p=10,q=20,r; if(r = p = 5 || q > 20) printf("%d",r); else printf("No output"); return 0; } ``` The output is 1 but how? Please explain
Precedence. To be more clear: ``` if(r = p = 5 || q > 20) ``` is the same as ``` if(r = p = (5 || q > 20)) ``` 5 is truthy, so the boolean expression evaluates to 1, which is then assigned tor
I get 'Permission denied' whenever I try to compile and run a program in Visual Studio code, in my Mac. How do I solve this? Note the 'permission denied' in this picture
You need to say something like ``` gcc -o film film.c ``` and then ``` ./film ``` film.cis your source file. In the example I've shown, the-oflag asksgccto put its output -- the compiled program -- in filefilm(with no conventional suffix).That'sthe file you want to run.
Does using fopen(fileName, "w") overwrite the blocks being used by a file, or does it set the blocks that were once being used as free and then start writing to new blocks?
The C standard doesn’t specify how it’s implemented. So, itmightoverwrite the blocks, but there’s no guarantee. On a Unix/Unix-like environment, for example, it’s most likely a wrapper aroundopen()with some internalFILE *manipulation that we need not worry about.
This question already has answers here:What is special about numbers starting with zero?(4 answers)Closed4 years ago. I was trying the following code ``` printf("%d", 010 % 10); ``` I was expecting it output be 0, but it is 8. Why? Is there any way to get the last digit of an integer which is taken as input.
Any numeric literal in c or c++ starting with a zero will be interpreted asoctal So your calculation is 8 modulo 10, which is 8
In GTK3, how do I get a DrawingArea to respond keyboard events? Should I connect the DrawingArea with a signal or is it more compicated? I'm using GTK3 with the C language.
I fianlly found the solutionhere. I only connected the signal, but the GTK_CAN_FOCUS also need to be set for the drawingrea.
Whenever I try to compile c/cpp files it gives this error: ``` gcc: fatal error: cannot execute ‘as’: execvp: No such file or directory compilation terminated. ``` I have also tried to include full path of file while compiling but same error occured. Just to be sure of version mismatch I looked for both gcc and g++ version but both are same, gcc/g++ version: 9.1.0. How can I fix this?
ascommand is frombinutils. Have you installed this package?
I want a C macro that will expand into a function with an extra parameter based on a condition. Something like this: ``` #define EXTRA 7 #ifdef ADD_ONE_MORE_ARG #define dothis(...) dothat(EXTRA,...) #endif ``` Such thatdothis(5);is expanded intodothat(EXTRA, 5);but I can't remember the syntax. TheanswerI found here didn't help. Thanks.
``` #define callx(...) call(EXTRA, __VA_ARGS__) ```
Can someone explain me please what is RTL in the context of driver development for Windows ? Development Tool : Visual studio 2019 Driver Type: Kernel Mode (kmdf). Programming Language : C.
Many kernel API functions start with theRtlprefix - that's an abbreviation of Run Time Library.
For example we have a server-client application. If the server write a message on the socket and then close it before the client's read. Will the client be able to read the message?
"If the server write a message on the socket and then close it before the client's read. Will the client be able to read the message?" Yes. The client will get the data that was sent before the FIN packet that closes the socket.
Can someone explain me please what is RTL in the context of driver development for Windows ? Development Tool : Visual studio 2019 Driver Type: Kernel Mode (kmdf). Programming Language : C.
Many kernel API functions start with theRtlprefix - that's an abbreviation of Run Time Library.
For example we have a server-client application. If the server write a message on the socket and then close it before the client's read. Will the client be able to read the message?
"If the server write a message on the socket and then close it before the client's read. Will the client be able to read the message?" Yes. The client will get the data that was sent before the FIN packet that closes the socket.
What does this statement mean in C language (assuming s1 and s2 are character arrays)? ``` (s1[i] = s2[i]) != '\0' ```
Consideringstrings are\0terminated by the standard. ``` (s1[i] = s2[i]) != '\0' ``` it will assigns2[i]tos1[i]then it will compare whether assigned value is\0or not. It is usually used to break the loop while copying contents from one string to another.
I'm trying to implement ElGamal cryptosystem and I decided to use OpenSSL to generate big primes. I've seen several functions that generate big random numbers but I haven't found a function to generate prime numbers. What function should I use?
That's a function of the underlying Big Number (BN) implementation rather than a specific high level crypto function, so I guess you'd useBN_generate_prime_ex.
I have a binary mask which at some point I'm updating. It's ok for 1s in my old mask to become 0s but the other way around is not allowed. How can I assert using some binary operations that none of the 0s in the mask have turned into 1s?
``` if (~old & new) ``` If you also want to know which bits changed from 0 to 1, just read each bit inbits = ~old & new;. If you just want to know if any 0s became 1s, that first line of code will do.
I have a binary mask which at some point I'm updating. It's ok for 1s in my old mask to become 0s but the other way around is not allowed. How can I assert using some binary operations that none of the 0s in the mask have turned into 1s?
``` if (~old & new) ``` If you also want to know which bits changed from 0 to 1, just read each bit inbits = ~old & new;. If you just want to know if any 0s became 1s, that first line of code will do.
I'm running this code and getting some garbage value while printing *ptr. What could be the possible reason and how can I avoid getting that? ``` # include <stdio.h> int main() { int test = 1; int *ptr = &test; *ptr++ = 10; test++; printf("\nThe value is %d", *ptr); } ```
You movedptrwithptr++. Why? Don't do that.
I know the C11 standard definesrsize_tassize_tin the optional Annex K, but in what header file(s)? Where does the C standard say this type should be defined?
K.3.3 Common definitions<stddef.h> The header<stddef.h>defines a type.The type isrsize_twhich is the typesize_t. Quoting thedraft. Reading further, this is also defined in<string.h>,<stdlib.h>,<stdio.h>,<wchar.h>and<time.h>. There may be others.
I know the C11 standard definesrsize_tassize_tin the optional Annex K, but in what header file(s)? Where does the C standard say this type should be defined?
K.3.3 Common definitions<stddef.h> The header<stddef.h>defines a type.The type isrsize_twhich is the typesize_t. Quoting thedraft. Reading further, this is also defined in<string.h>,<stdlib.h>,<stdio.h>,<wchar.h>and<time.h>. There may be others.
I'm looking atunsigned char(byte) arrays ingdb, i.e. ``` (gdb) p/x buf@4 $76 = {0xac, 0xa, 0xb0, 0xa} ``` Is there a way of forcing the preceding 0s? i.e output like: ``` $76 = {0xac, 0x0a, 0xb0, 0x0a} ```
From the gdbdocumentation: 'z'Like 'x' formatting, the value is treated as an integer and printed as hexadecimal, but leading zeros are printed to pad the value to the size of the integer type. So... ``` (gdb) p/z buf@4 ```
I'm wondering if the fopen command is smart enough to stop reading a file if it's to large and then wait for some proceeding read command to continue reading. For that matter, how large is _iobuf?
fopen(...)doesn't do any size checks; it just returns a file pointer. Are you thinking offread(...), by any chance? You can always find the size of the file that you are going to read by usingstat(...)system call.
I'm trying to get the most significant bit of an unsigned 8-bit type in C. This is what I'm trying to do right now: ``` uint8_t *var = ...; ... (*var >> 6) & 1 ``` Is this right? If it's not, what would be?
To get the most significant bit from a memory pointed to byuint8_tpointer, you need to shift by 7 bits. ``` (*var >> 7) & 1 ```
I would like to know how to define a char array, in C, of three elementsa,b,c, whereais located on one first octet,bin one second andcin one third.
Well, In C, the size ofcharit's 1. I think we can't know if it's 1 octet or more (or less). So, ``` char tab[3] = {'a','b','c'}; ``` doesn't work ?
When I build a simple console app with clang, it works fine: void main() { puts("HELLO"); } But when I create a Windows app withWinMain, I can't see stdout. There must be a flag that fixes it, like MinGW's-mconsole
A quick stdout-enabler for otherwise GUI apps: ``` if (AllocConsole()) { FILE* fi = 0; freopen_s(&fi, "CONOUT$", "w", stdout); } ``` and thenstd::coutandprintfwork.
always the first line of my file is empty whst can i do ? ``` printf("donner n"); scanf("%d",&n); for(int i=0;i<n;i++) { gets(ch); fprintf(f,"%s\n",ch);} ``` ```
change ``` scanf("%d",&n); ``` to ``` scanf("%d\n",&n); ``` Should be able to get the results you want Because the first empty line is a newline character that is not read at scanf.
always the first line of my file is empty whst can i do ? ``` printf("donner n"); scanf("%d",&n); for(int i=0;i<n;i++) { gets(ch); fprintf(f,"%s\n",ch);} ``` ```
change ``` scanf("%d",&n); ``` to ``` scanf("%d\n",&n); ``` Should be able to get the results you want Because the first empty line is a newline character that is not read at scanf.
I'm trying to read from a .csv file in C and it works for my character arrays, but not for my long. ``` char fname[24]; char lnem[48]; char email[36] long phone; fscanf(fp, "%[^,],%[^,],%[^,]%*s,%lf", fname, lname, email, phone); ```
The line should be ``` fscanf(fp, "%[^,],%[^,],%[^,],%ld", fname, lname, email, &phone); // removed %*s ----^ ^---- format specifier ^---- address-of operator ```
I am trying to setup my eclipse to run some C but there is this long tool in the toolbar which i am not even using and I do not know how to disable it. Can someone help me please?
This isWindow|perspective|customise|Tool Bar Visibility Perhaps this is a clue (photon launch bar): https://www.eclipse.org/forums/index.php/t/1095011/ They suggest it is on the launch bar preference page.
I want to put the value of anarrayinto a float integer. ``` main(){ float a; char array[4]="12.1"; a=atoi(array); printf("%f",a); } ``` When I uses this program, it gives12.000000as output but I want12.100000as output. Thanks in advance.
Use of this : atof()— Convert Character String to Float : ``` #include <stdlib.h> double atof(const char *string); ``` This linkexplains about that.
Was working with some SASL code today and noticed the==in the below snippet. I'm no C expert but the only way I've ever used that operator was to test equality. Bug? ``` if ( !conn ) { rc == LDAP_SUCCESS; goto done; } ```
That statement does nothing. It's a bug. Now, you COULD assign (rc == LDAP_SUCCESS) to a variable, which would store the boolean result of that operation (1 if true, or 0 if false).
I use Windows Subsystems for Linux(WSL), Ubuntu. I try compile simple code. I get errors in WSL. But, it works well in Visual Studio.
gets_s()is a "secure" alternative togets()defined in the Microsoft C Runtime Library. It is not included in the GNU C library used in Linux. For portability usefgets()on thestdininput stream instead.
I use Windows Subsystems for Linux(WSL), Ubuntu. I try compile simple code. I get errors in WSL. But, it works well in Visual Studio.
gets_s()is a "secure" alternative togets()defined in the Microsoft C Runtime Library. It is not included in the GNU C library used in Linux. For portability usefgets()on thestdininput stream instead.
This question already has answers here:How are floating point numbers stored in memory?(7 answers)Closed4 years ago. If we create one variable of data type float and assign any value to it then how this is stored in memory? float var = 13.34;
Float is a 4-byte size type, which consist of sign, exponent and mantissa (described in IEEE 754). The last bit represents sign, 8 followed bits are exponent and rest are mantissa.
This question already has answers here:How are floating point numbers stored in memory?(7 answers)Closed4 years ago. If we create one variable of data type float and assign any value to it then how this is stored in memory? float var = 13.34;
Float is a 4-byte size type, which consist of sign, exponent and mantissa (described in IEEE 754). The last bit represents sign, 8 followed bits are exponent and rest are mantissa.
So I havechar **sentencewithsentence[0] = string0, sentence[1] = string1, etc. Is there a way I can print the entire array in lldb? So that it shows up as{string0, string1, ...}
This is answered in: View array in LLDB: equivalent of GDB's '@' operator in Xcode 4.1 particularly, you can use theparraycommand in any recent lldb. There isn't a way to do this in the Xcode Locals view, but you can do this in the Xcode Debugger Console.
So I havechar **sentencewithsentence[0] = string0, sentence[1] = string1, etc. Is there a way I can print the entire array in lldb? So that it shows up as{string0, string1, ...}
This is answered in: View array in LLDB: equivalent of GDB's '@' operator in Xcode 4.1 particularly, you can use theparraycommand in any recent lldb. There isn't a way to do this in the Xcode Locals view, but you can do this in the Xcode Debugger Console.
``` (gdb) set disassemble intel Ambiguous set command "disassemble intel": disassemble-next-line, disassembler-options. ``` When i set the disassembly syntax to intel, it show this error.
Please use: ``` set disassembly-flavor intel ``` seeGDB Manualfor more details
I have existing C program which i want to call from tibco bw6. Is there any direct approach, like bw allow to invoke java code. One possible solution is to use java invoke and jni. Direct call will be more preferable if possible
if you have the .exe file you can use External Command activity otherwise I do not see any other simple solutions than to use swig with jni. Regards
I was wondering if there is a way to run a random statement in C that I created, such as a function. I know how to run a random integer but not how to randomly pick from a list of statements that I created.
you can do like this with yourrandomValuethat you got fromrand()function: ``` int statement = randomValue % nState; ``` in above code, I assume that your program havenSatestates and you can use this variable in yourswitch.
In system programming class, we are told that all system calls are made in c. For example opening a file for reading/writing. Does java run c codes behind?
Yes java runs C Code behind the scene. Using the native keyword. For Instance: System.currentTimeMillis() is a Native Method Here is a good explaination how to use Native code:https://www.baeldung.com/java-native
In system programming class, we are told that all system calls are made in c. For example opening a file for reading/writing. Does java run c codes behind?
Yes java runs C Code behind the scene. Using the native keyword. For Instance: System.currentTimeMillis() is a Native Method Here is a good explaination how to use Native code:https://www.baeldung.com/java-native
My code uses ZLIB, and it seems that there are problems in usingfmemopen()and ZLIB functions afterwards... Is there an equivalent offmemopen()in ZLIB? Or how can I create it if no equivalent exists?
No there is not. Furthermore, there is no need for such a thing, since zlib provides in-memory functions for compression and decompression.
I'm reading the C Programming Language (chapter 5), and I'm confused by this example: ``` int n, array[SIZE], getint(int *); ``` Why is this function call in here like that? Is this just some tricky example and invalid code?
It's not calling the function; it's declaring its prototype. It's equivalent to: ``` int n; int array[SIZE]; int getint(int*); ```
``` a[b] ``` Is equivalent to*(a + b), so... ``` a[b & c] ``` Where&has a lower operator precedence than+, would this result in*(a + b & c)or*(a + (b & c))?
TheC Standard, § 6.5.2.1,Array Subscriptingsays: The definition of the subscript operator[]is thatE1[E2]is identical to(*((E1)+(E2))) Note the brackets surroundingE2. The latter expression (*(a + (b & c))) is the correct outcome.
I'm currently creating a little game, and I need to create a condition. In pseudo-code, it would look like something like this : ``` if (a < x with x included in [b -10; b +10]) { then c = 2 } ``` Is there an easy way to do this ? I know it may not be really clear, so ask me further details if you didn't understand.
``` if(a < x && x >= b-10 && x <= b + 10){ } ```
I'm currently creating a little game, and I need to create a condition. In pseudo-code, it would look like something like this : ``` if (a < x with x included in [b -10; b +10]) { then c = 2 } ``` Is there an easy way to do this ? I know it may not be really clear, so ask me further details if you didn't understand.
``` if(a < x && x >= b-10 && x <= b + 10){ } ```
Is it bad practice when I assign new pointer to pointer without free? ``` char **arr = malloc(sizeof(*arr)*9); ... ... arr[5] = strdup("sys"); arr[6] = strdup("var"); arr[7] = strdup("home"); arr[8] = NULL; arr[5] = arr[6]; arr[6] = arr[7]; arr[7] = NULL; ```
Yes. Since that pointer you reassigned (e.g. arr[5]) is no longer accessible it's memory can't be free'd and it is a memory leak.
I just did this ``` printf( (n==0) ? " %d" : " %3d", n ); ``` but is there a conditional format descriptor? So, it would mean something like"if this is very short use such and such padding, but, if this is longer use such and such padding." Can do?
There's no conditional, but you can use * to specify the width in the arguments. e.g.: ``` printf(" %*d", (n==0)?1:3, n); ```
In a Windows application, I have aGetFirmwareEnvironmentVariableAfunction to read a firmware environment variable. Is there any way to write something in this variable in uefi driver and read from it later in Windows?
The function to set an NVRAM variable is called SetVariable() and is available to UEFI drivers via EFI_RUNTIME_SERVICES table. To know more about it's interface and usage, read chapter 7.2 Variable Services of theUEFI 2.6 specification.
Are there any different between those both (ptrfun1andptrfun2)? ``` int fun(int num){ num *= num; return num; } int main(){ int (*ptrfun1)(int num) = fun; int (*ptrfun2)(int num) = &fun; ``` Does both point to the functionfun?
There is no difference at all. A functiondecaysto a function pointer.
Are there any different between those both (ptrfun1andptrfun2)? ``` int fun(int num){ num *= num; return num; } int main(){ int (*ptrfun1)(int num) = fun; int (*ptrfun2)(int num) = &fun; ``` Does both point to the functionfun?
There is no difference at all. A functiondecaysto a function pointer.
What is the specifier%[^s]used for? sis a variable. In which cases can I use this specifier?
The%[format specifier toscanfwill match a sequence of characters matching those that are listed between[and]. If the first character is^, then it matches charactersexcludingthose characters. In your case%[^s]means "match any character besides the characters's'.sisnota variable in this case.
I don't fully understand how the "-" operator affects the following code: ``` #define COMP(x) ((x) & -(x)) unsigned short a = 0xA55A; unsigned short b = 0x0400; ``` Could someone explain what COMP(a) and COMP(b) are and how they are calculated?
(x) & -(x)is equal to the lowest bit set inxwhen using 2's complement for representing binary numbers. This meansCOMP(a) == 0x0002;andCOMP(b) == 0x0400;
I'd like to look at the source code Apache uses to process .htaccess files. I've downloaded and grepped the Apache source files with no luck.
I'm suspicious of your ability to grep.. I just downloaded the httpd source and it mentionshtaccesseverywhere. Why not start by looking at the functionap_parse_htaccessdefined inserver/config.c.