question
stringlengths
24
425
answer
stringlengths
5
405
There is good documentation here (http://www.postgresql.org/docs/8.3/static/xfunc-c.html), but I didn't find a way to read/modify/delete data from existing table by tablename and columns name from C extension.
I guess what you need isSPI. P. S. Do you actually use 8.3? Use the latest (9.4) if you're not restricted somehow.
In a single nibble (0-F) I can store one number from 0 to 15. In one byte, I can store a single number from 0 to 255 (00 - FF). Can I use a byte (00-FF) to store two different numbers each in the range 0-127 (00 - 7F)?
The answer to your question is NO. Youcansplit a single byte into two numbers, but the sum of the bits in the two numbers must be <= 8. Since, the range 0-127 requires 7 bits, the other number in the byte can only be 1 bit, i.e. 0-1.
``` int m,digit[100],i=0, n = 15; while(n) { m = n%2; digit[i] = "0123456789abcdefghijklmnopqrstuvwxyz"[m]; n = n/2; } ``` I did not understand what is digit[i] = "0123456789abcdefghijklmnopqrstuvwxyz"[m];
digit[i] ="0123456789abcdefghijklmnopqrstuvwxyz"[m];is themth letter of0123456789abcdefghijklmnopqrstuvwxyz.
When I resize my window and aWM_SIZEmessage is sent, does theWM_SIZEmessage get sent to the message queue or does the window procedure called directly?
Resizing a window by mouse sendsWM_SIZEdirectly to the window procedure, it does not go through the message queue.
There is good documentation here (http://www.postgresql.org/docs/8.3/static/xfunc-c.html), but I didn't find a way to read/modify/delete data from existing table by tablename and columns name from C extension.
I guess what you need isSPI. P. S. Do you actually use 8.3? Use the latest (9.4) if you're not restricted somehow.
In a single nibble (0-F) I can store one number from 0 to 15. In one byte, I can store a single number from 0 to 255 (00 - FF). Can I use a byte (00-FF) to store two different numbers each in the range 0-127 (00 - 7F)?
The answer to your question is NO. Youcansplit a single byte into two numbers, but the sum of the bits in the two numbers must be <= 8. Since, the range 0-127 requires 7 bits, the other number in the byte can only be 1 bit, i.e. 0-1.
``` int m,digit[100],i=0, n = 15; while(n) { m = n%2; digit[i] = "0123456789abcdefghijklmnopqrstuvwxyz"[m]; n = n/2; } ``` I did not understand what is digit[i] = "0123456789abcdefghijklmnopqrstuvwxyz"[m];
digit[i] ="0123456789abcdefghijklmnopqrstuvwxyz"[m];is themth letter of0123456789abcdefghijklmnopqrstuvwxyz.
When I resize my window and aWM_SIZEmessage is sent, does theWM_SIZEmessage get sent to the message queue or does the window procedure called directly?
Resizing a window by mouse sendsWM_SIZEdirectly to the window procedure, it does not go through the message queue.
``` #include <stdio.h> int main(void) { char *s = "Jordan"; printf("hello, %s\n, s"); } ``` Does anyone know a way that I can get this native C source code to work? I'm having trouble getting it to compile and run.
Your second quote is in the wrong place. Try: ``` printf("hello, %s\n", s); ```
Does gethostbyaddr() function uses internet connection for converting ip address to hostname? Or it uses some cached data (like DNS cache)?
Yes. It does a DNS lookup, which may be satisfied by the local resolver's cache or may not.
``` void main() { int a; a=10; do while(a++<10); while(a++<=11); printf("%d",a); } ``` The above program gives an output of14. Can you please explain why?
This code will make you understand why , Whenever you type a++ its always incremented ``` void main() { int a; a=10; do{ while(a++<10); printf("%d",a); } while(a++<=11); printf("%d",a); } ```
``` #include <stdio.h> void main() { char *s= "hello"; char *p = s; printf("%c\t%c", p[0], s[1]); } ``` output of this program is : h e Can anyone please explain how this program is working? I'm relatively new to c..
p[0]is identical to*(p+0), similarly goes fors[1].[]always operates on a pointer and is same for arrays and pointers. Note- There is no array declared in your program.
``` #include <stdio.h> void main() { char *s= "hello"; char *p = s; printf("%c\t%c", p[0], s[1]); } ``` output of this program is : h e Can anyone please explain how this program is working? I'm relatively new to c..
p[0]is identical to*(p+0), similarly goes fors[1].[]always operates on a pointer and is same for arrays and pointers. Note- There is no array declared in your program.
``` #include <stdio.h> void main() { char *s= "hello"; char *p = s; printf("%c\t%c", p[0], s[1]); } ``` output of this program is : h e Can anyone please explain how this program is working? I'm relatively new to c..
p[0]is identical to*(p+0), similarly goes fors[1].[]always operates on a pointer and is same for arrays and pointers. Note- There is no array declared in your program.
I need to find the length of an array, how would I do this without using thesizeoffunction. eg if ``` Array 1 = [0 1 2 3 4 5 6] ``` the size of this array would be7.
If you can't usesizeof(tell us why, please), you can use a loop and a sentinel (-1 or some number that can not be used in the array): ``` int arr[] = {0, 1, 2, 3, 4, 5, 6, -1}; int count = 0; while (arr[count] != -1) count++; ```
I need to find the length of an array, how would I do this without using thesizeoffunction. eg if ``` Array 1 = [0 1 2 3 4 5 6] ``` the size of this array would be7.
If you can't usesizeof(tell us why, please), you can use a loop and a sentinel (-1 or some number that can not be used in the array): ``` int arr[] = {0, 1, 2, 3, 4, 5, 6, -1}; int count = 0; while (arr[count] != -1) count++; ```
I have an function address stored in anunsigned int, and a function pointer. Now i want thatfunction_pointerwill contain the value offunction_address ``` unsigned int function_address = 0xdeadbeef; void(*function_pointer)(void) = function_address; // not valid ``` how to do that in C ?
Perform an explicit cast. ``` void(*function_pointer)(void) = (void (*)(void))function_address; ```
Is there any doc i can read about this kind of function? ``` // return the capital of char c char a(char c){ return c >= 'a' && c<='z' ? c +'A' - 'a':c; } ```
Read up on the ternary operator. :) And then it will be clear the code is doing: ``` if (c >= 'a' && c<='z') { return(c +'A' - 'a'); } else { return c; } ``` So basically it is capitalizing the Latin alphabet in ASCII.
This question already has answers here:Type of #define variables(7 answers)Closed7 years ago. When I define a numerical constant with#define(e.g.#define pi 3.141593) is it anint,float,doubleor what?
Neither. It is a lexicographical replacement, that is, it will replacepiwith3.141593wherever it shows up.
I have an function address stored in anunsigned int, and a function pointer. Now i want thatfunction_pointerwill contain the value offunction_address ``` unsigned int function_address = 0xdeadbeef; void(*function_pointer)(void) = function_address; // not valid ``` how to do that in C ?
Perform an explicit cast. ``` void(*function_pointer)(void) = (void (*)(void))function_address; ```
Is there any doc i can read about this kind of function? ``` // return the capital of char c char a(char c){ return c >= 'a' && c<='z' ? c +'A' - 'a':c; } ```
Read up on the ternary operator. :) And then it will be clear the code is doing: ``` if (c >= 'a' && c<='z') { return(c +'A' - 'a'); } else { return c; } ``` So basically it is capitalizing the Latin alphabet in ASCII.
Just curious, why below code is not equivalent to forever loop? Instead application crashes. ``` unsigned short i; for (i = 1; i >= 0; i++) { printf("%d\n", i); } ```
The problem is solved. Antivirus Karspersky was analysing this exe file for nearly 20 seconds it looks. If I disable antivirus, it runs immediately. Thanks for all your inputs.
Just curious, why below code is not equivalent to forever loop? Instead application crashes. ``` unsigned short i; for (i = 1; i >= 0; i++) { printf("%d\n", i); } ```
The problem is solved. Antivirus Karspersky was analysing this exe file for nearly 20 seconds it looks. If I disable antivirus, it runs immediately. Thanks for all your inputs.
How can we do transaction signing in mozilla firefox by loading PKCS#11 library to database. after some research i found about capicom library. but the thing is this library does not support with windows7 and higher versions.
you cannot use c code but you can do the same by java applets which are to be signed. Please referhttp://www.nakov.com/books/signatures/Java-for-Digitally-Signing-Documents-in-Web-book-Nakov.html
What happens in the follwing code, does program executes 'return 1' or exits before? ``` int cmd_quit(tok_t arg[]) { printf("Bye\n"); exit(0); return 1; } ```
exit()ends the program, no matter what. So: no. In practice, a C runtime will always do something similar of ``` exit(main(argc, argv)); ``` to execute your program. (meaning:ifmain()returns,exit()will be called automatically with its return value)
How do I get1.371429as01.37. Is it not%2.02f? I need to have a leading zero and also round it to two decimal places.
Try this: ``` #include<stdio.h> int main() { double a = 1.2345666; printf("%05.2lf\n", a); return 0; } ``` Here,05says "print 5 columns with leading zeros"..2says "print decimal digits untill 2 columns". 2 decimal digits + 1.+ 2 integer part => total 5 columns you have to print.
What happens in the follwing code, does program executes 'return 1' or exits before? ``` int cmd_quit(tok_t arg[]) { printf("Bye\n"); exit(0); return 1; } ```
exit()ends the program, no matter what. So: no. In practice, a C runtime will always do something similar of ``` exit(main(argc, argv)); ``` to execute your program. (meaning:ifmain()returns,exit()will be called automatically with its return value)
How do I get1.371429as01.37. Is it not%2.02f? I need to have a leading zero and also round it to two decimal places.
Try this: ``` #include<stdio.h> int main() { double a = 1.2345666; printf("%05.2lf\n", a); return 0; } ``` Here,05says "print 5 columns with leading zeros"..2says "print decimal digits untill 2 columns". 2 decimal digits + 1.+ 2 integer part => total 5 columns you have to print.
I have the following: ``` char rank[100][100]; int score = 5; strcpy(rank[0], "%d" score); ``` However,strcpy()does not accept these arguments. Is there any way to append a formatted string into my array?
You could usesprintf: ``` char rank[100][100]; int score; sprintf(rank[0], "%d", score); ``` Note however thatsnprintfis the buffer overflow-safe alternative.
For example there is a method dog: ``` void dog(char C,int N) { //here if I want to print the value of C with a print statement,how do I do that? } ```
What about a ``` printf("the value of c = %c\n", C); ```
How can I remove opened file in linux? In shell I can do this: ``` rm -rf /path/to/file_or_directory ``` But how can I do it in C? I don't want to usingsystem()function. I have seen unlink and remove method but it's haven't any flags to set force deletion.
Theunlinkandremovefunctions force deletion. Thermcommand is doing extra checksbeforeit calls one of those functions. But once you answery, it just uses that function to do the real work.
How can I remove opened file in linux? In shell I can do this: ``` rm -rf /path/to/file_or_directory ``` But how can I do it in C? I don't want to usingsystem()function. I have seen unlink and remove method but it's haven't any flags to set force deletion.
Theunlinkandremovefunctions force deletion. Thermcommand is doing extra checksbeforeit calls one of those functions. But once you answery, it just uses that function to do the real work.
please i can't understand the while loop , why the loop show A two time and not one ``` char *s,*t; s="ABC"; t="AA"; do {printf("A");} while(*s++==*t++); printf("%d %d",*s-*t); ```
In your code ``` printf("%d %d",*s-*t); ``` invokes undefined behavior as you're not supplying enough argument to sate the supplied format specifiers.
I am using the source file fromhttps://github.com/contiki-os/contikiI added a new directory (say/foo) that includes some .c and .h files I need to use them onexamples/cc26xx, although I included the .h files (under/foo) to cc26xx-demo.c, it doesn't really include the files when I runmake can anyone tell me how do I need to include them either onexamples/cc26xx/MakefileorMakefile.include
addingPROJECT_SOURCEFILES += mylib.cto Makefile solved the issue.
I am using the source file fromhttps://github.com/contiki-os/contikiI added a new directory (say/foo) that includes some .c and .h files I need to use them onexamples/cc26xx, although I included the .h files (under/foo) to cc26xx-demo.c, it doesn't really include the files when I runmake can anyone tell me how do I need to include them either onexamples/cc26xx/MakefileorMakefile.include
addingPROJECT_SOURCEFILES += mylib.cto Makefile solved the issue.
While I was looking for MMX functions, I noticed that two of them,_m_emptyand_mm_empty, haveexactly the same definition. So why do they both exist ? Is one of them older than the other ? Is there a difference that is not mentioned in the manual ?
Differences would/should be pointed out in the documentation. TheMSDNis more precise. They explicitly mention this: A synonym for_mm_emptyis_m_empty.
I want to reduce the resolution of a video from 1024*768 to 800*600. I found on the web ffmpeg, and the library swscale (I use in C. And I found some informations on the web, but nothing about how to reduce the resolution of a video nor about which functions to use How can I do ?
Seethisorthisexample code. Usesws_getContext() to set up a scaler, andsws_scale() to convert one frame or slice.
I just created new console application project byDev-C++ 4.9.9.2. But Project Options(Alt+P) not working andError: Access violation at address 0012F64B. Write of address 0012F64B. How to fix this problem.
Its Dev-C++ problem , update it .Details
I just created new console application project byDev-C++ 4.9.9.2. But Project Options(Alt+P) not working andError: Access violation at address 0012F64B. Write of address 0012F64B. How to fix this problem.
Its Dev-C++ problem , update it .Details
According tothisquestion, gcc's-lcommand requires your library to be named libXXX.a. Is there a way to link a static library using a different command with gcc? The goal is to avoid this lib- prefix.
Just pass the library as in input file like so: ``` gcc main.c yourlibrary.a -o prog ```
In ubuntu I would do it by following command ``` ./a.out < input.txt | cat > ouput.txt ``` how can I do this in Windows cmd?
You can do it in two lines: ``` a.exe < input.txt >output.txt type output.txt ```
In ubuntu I would do it by following command ``` ./a.out < input.txt | cat > ouput.txt ``` how can I do this in Windows cmd?
You can do it in two lines: ``` a.exe < input.txt >output.txt type output.txt ```
I have a variable i: ``` int i; if(b){ i=1; } else{ i=-1; } ``` Isiundefined behavior because ofint i;exists? Or Should we alwaysint i=0first?
Absolutely fine. You are initialisingion all program control paths, and not reading the value until initialisation is complete. I prefer using the ternary operator in such instances. int i = b ? 1 : -1; as that's less vulnerable to accidental reference to an uninitialisedi.
``` #include <stdio.h> #include <stdlib.h> int main() { FILE * fp; fp = fopen ("file.txt", "w+"); fclose(fp); return(0); } ``` the above programs will create a file . i need that file needs to be placed in specific directory. please help
Add path into the parameter offopen(). ``` fp = fopen ("/path/to/file.txt", "w+"); ```
What does this macro mean or what is the result? ``` #define MOD_TYPE_12 0x11, 0x20, 0x0C, 0x00, 0x02, 0x00, 0x07, 0x0F, 0x42, 0x40, 0x01, 0xC9, 0xC3, 0x80, 0x00, 0x02 ``` Is this evaluated to an array? I couldn't find anything... Maybe because I don`t know what I have to search for ^^
All the MOD_TYPE_12 in your program will be replaced with 0x11, 0x20, 0x0C There is no specialty with commas
I remember being constantly told that the C preprocessor does not know C. It doesn't know about types, doesn't remember declared symbols, etc. If that's the case, how can it possibly act differently based on the type of its parameter?
The_Genericfeature is not processed by the preprocessor. It is aprimary expressionthat is treated with higher preference than most other expressions.
Is there anything similar to Java's Integer.MIN_VALUE in C, which gives the smallest possible value of a signed integer, or do I just have to hard code the value myself?
You can uselimits.hhttp://en.cppreference.com/w/c/types/limits I think this is what you're looking for:INT_MIN = minimum value for an int
My goal is to parse potentially garbled ASCII data containing text and numbers. So far I've been doing fine with getting a pointer to numbers within the text withstrcmpand hard-coded pointer arithmetic and then converting them withstrtol, but I feel there must be a better way. Is there a function with the effect ofscanfwhich takes a pointer to memory instead of input stream?
You'll be wantingsscanf. Note that it does expect a null-terminated string.
I have a string which captures details stored indata User 6%, System 18%, IOW 0%, IRQ 0% What i am doing is sscanf(data,"User %d,System %d,IOW %d,IRQ %d",&user,&sys,&iow,&irq); I am getting wrong output . why ? Is is like i am missing something ?
You left out the%symbols and some spaces - try: ``` sscanf(data,"User %d%%, System %d%%, IOW %d%%, IRQ %d%%",&user,&sys,&iow,&irq); ```
My goal is to parse potentially garbled ASCII data containing text and numbers. So far I've been doing fine with getting a pointer to numbers within the text withstrcmpand hard-coded pointer arithmetic and then converting them withstrtol, but I feel there must be a better way. Is there a function with the effect ofscanfwhich takes a pointer to memory instead of input stream?
You'll be wantingsscanf. Note that it does expect a null-terminated string.
I have a situation where i have to callwake_up_interruptible()on a wait queue, which may not holding any process to sleep. Is it ok to callwake_up_interruptible()on an unused wait queue ?
Yes, as long as the queue is initialized you are fine.
What does this expression mean: ``` typedef char foo [FOO]; ``` I am just struggeling with the meaning of the expression between the squared brackets.
It readsfoois the type of an array ofFOO-manycharelements. In this case,FOOis a constant, defined somewhere as#define FOO 100 ``` typedef int pair[2]; // Pair is an array of two ints. ```
I have a situation where i have to callwake_up_interruptible()on a wait queue, which may not holding any process to sleep. Is it ok to callwake_up_interruptible()on an unused wait queue ?
Yes, as long as the queue is initialized you are fine.
A code snippet is as follows: ``` struct wer { unsigned int a:5; unsigned int:0; unsigned int b:3; unsigned int c:2; unsigned int:0; }v; ``` I know that all of these are packed bit fields but how to find the storage which would be needed for v.
You can get the storage required forvusingsizeof(v).
A code snippet is as follows: ``` struct wer { unsigned int a:5; unsigned int:0; unsigned int b:3; unsigned int c:2; unsigned int:0; }v; ``` I know that all of these are packed bit fields but how to find the storage which would be needed for v.
You can get the storage required forvusingsizeof(v).
I am trying to set a bit in a 8 bit variable. Every time I print the variable after setting a particular bit , I always get the value as 1. ``` uint8 value; value = (1<<1 || value) printf(%x \n,value); //prints 1 instead of 2 value = (1<<2 || value) printf(%x \n,value); //prints 1 instead of 4 ```
You're using boolean 'or'||. Bitwise 'or' is|. Also you haven't initializedvalueso you can't expect it to be anything.
I have a struct that I want to zero and then set the members. I tried this: ``` cmdRequest_t cmdRequest = {0}; cmdRequest = {3, "d t"}; ``` but that doesn't work. I have also tried several variants, but I always get a syntax error on that second line. How can I do this?
Simply do: ``` cmdRequest_t cmdRequest = {3, "d t"}; ``` There's no need to zero the structure if you're going to immediately fill in other values.
I have not really a programming issue but more like an IDE issue. My Eiffel Studio 15.01 won't start up because of this error shown on the picture in the link.https://i.stack.imgur.com/mCzrO.jpg Can anybody help please?
You can try to go to menu View > Tools Layout > Reset Tools Layout Otherwise remove the files under %LOCALAPPDATA%\Eiffel Software\.es\15.01\docking (or ~/.es/15.01/docking in linux) And restart EiffelStudio.
I have not really a programming issue but more like an IDE issue. My Eiffel Studio 15.01 won't start up because of this error shown on the picture in the link.https://i.stack.imgur.com/mCzrO.jpg Can anybody help please?
You can try to go to menu View > Tools Layout > Reset Tools Layout Otherwise remove the files under %LOCALAPPDATA%\Eiffel Software\.es\15.01\docking (or ~/.es/15.01/docking in linux) And restart EiffelStudio.
I need a regex that will match 24 time format. Eg2300is valid2900is not valid I was using this: ``` _[0-2][0-3][0-5][0-9]_ ``` But this doesn't allow _1900_etc_
You need to decompose thehourspart in two cases: from00to19and from20to23. This is done by using a(pattern1|pattern2)expression. Hours: 00-23. ``` ([01][0-9]|2[0-3]) ``` Minutes: 00-59. ``` [0-5][0-9] ``` All together: ``` ([01][0-9]|2[0-3])[0-5][0-9] ```
Question speaks for itself. I have a program that used SHBrowseforfolder, but now they want me to upgrade it to IFileDialog which I made but is in C++, so is it even possible to get it to work with C since it's OOP?
IFileDialog is part of Microsoft's Component Object Model (COM). COM programming can be done in C. Quite tedious though. Here's a tutorial (can't vouch for it's quality) http://www.codeproject.com/Articles/13601/COM-in-plain-C
Question speaks for itself. I have a program that used SHBrowseforfolder, but now they want me to upgrade it to IFileDialog which I made but is in C++, so is it even possible to get it to work with C since it's OOP?
IFileDialog is part of Microsoft's Component Object Model (COM). COM programming can be done in C. Quite tedious though. Here's a tutorial (can't vouch for it's quality) http://www.codeproject.com/Articles/13601/COM-in-plain-C
This question already has answers here:Does it ever make sense to make a fundamental (non-pointer) parameter const?(5 answers)Closed8 years ago. Taking the following example: ``` void foo(const int foobar); ``` Is the keywordconstmeaningful?
Yes, obviously. Your functionfoo()will not be able to modify the valuefoobarinside the function.
This question already has answers here:Does it ever make sense to make a fundamental (non-pointer) parameter const?(5 answers)Closed8 years ago. Taking the following example: ``` void foo(const int foobar); ``` Is the keywordconstmeaningful?
Yes, obviously. Your functionfoo()will not be able to modify the valuefoobarinside the function.
This question already has answers here:Does it ever make sense to make a fundamental (non-pointer) parameter const?(5 answers)Closed8 years ago. Taking the following example: ``` void foo(const int foobar); ``` Is the keywordconstmeaningful?
Yes, obviously. Your functionfoo()will not be able to modify the valuefoobarinside the function.
Lets say I have achar[10]="1234567890. I want it to break it in two 5digits number. I want to ask two thing that do i need to convert it in int before spliting and how will i split it
ex ``` char num10[]="1234567890"; int n1, n2; sscanf(num10, "%5d%5d", &n1, &n2); printf("%d, %d\n", n1, n2); ```
I Want to get the username or SID from a session id value, how can I do that working from Window XP using the WinAPI?
You can use theWTSQuerySessionInformationfunctionto get the Username and Domain (WTSUserNameandWTSDomainNamefromWTS_INFO_CLASS). This function is available as far back as Windows 2000.
I couldn't disable it even though by using-std=c89flag. How can I disable it?
You can generate an error for variable length arrays using a compiler flag: ``` -Werror=vla ```
I couldn't disable it even though by using-std=c89flag. How can I disable it?
You can generate an error for variable length arrays using a compiler flag: ``` -Werror=vla ```
I want execute a code only one time. I used a solution based on a global varibale of bool type. My question, is it the best solution? Remark: I use ucos-II. ``` if (TRUE == Lock) { /*Code to execute one time*/ } /*The reste of the code*/ ```
A simple code using a static variable. ``` static bool once = false; if (once == false) { once = true; // do your "once" stuff here } ```
Is the memory allocation system of C completely random or does it use pseudo random generator ? What is the actual algorithm for memory allocation that happens at the back ?
C doesn't do memory allocation.You, the programmer, have to do it yourself based on the simple primitivesmalloc()andfree(), which do nothing but ask the OS for free chunks of memory to give you.
The problem is that on one platform (windows, mvsc2015)uint64_tis defined asunsigned long longand on another (ubuntu, clang) it'sunsigned longand there is the code which looks likesprintf(buffer, "%#llx", u64key);
The solution is to use C99's format macros, in particularPRIu64for anuint64_t: ``` #include <inttypes.h> … sprintf(buffer, "%#" PRIu64 "\n", u64key); ```
What's the meaning of: ``` #include <stdio.h> int main(){ double bmax = 31.4159265; printf("%1.4e\n", bmax); } ``` What is the meaning of%1.4e? I know%ffor double.
``` %e specifier is used to print value of float\double in exponential format. ``` So here%1.4ewill print 1 digit before the decimal point and 4 digits after the decimal point. So ifbmax=12.242then the output will be1.2242e+01.
I'm trying to build vp8 for android armv6 but with no luckI tried to set --target=armv6-android-gcc but i get Unrecognized toolchain 'armv6-android-gcc' errorbut --target=armv7-android-gcc works just fine.how should i do it ?
There is no ARM6 Android ABI in the NDK. ARM6 Android devices use the ARM5 ABI (which is the plain androideabi).
What's the meaning of: ``` #include <stdio.h> int main(){ double bmax = 31.4159265; printf("%1.4e\n", bmax); } ``` What is the meaning of%1.4e? I know%ffor double.
``` %e specifier is used to print value of float\double in exponential format. ``` So here%1.4ewill print 1 digit before the decimal point and 4 digits after the decimal point. So ifbmax=12.242then the output will be1.2242e+01.
I'm trying to build vp8 for android armv6 but with no luckI tried to set --target=armv6-android-gcc but i get Unrecognized toolchain 'armv6-android-gcc' errorbut --target=armv7-android-gcc works just fine.how should i do it ?
There is no ARM6 Android ABI in the NDK. ARM6 Android devices use the ARM5 ABI (which is the plain androideabi).
what is __dirstream, where can we find the definition So, I'm trying to get the sizeof DIR from opendir, which is a typedef of __dirstream. I understand it's hidden at compile-time, is there a defined max size?
That__double-underscore in the name marks it as implementation-private. Nothing is defined about it except what the implementation documents. is there a defined max size Nope, sorry.
The below program redirects all my output to log file. I need to display all the output along with log file. How can this be achieved? ``` $ gcc test.c $ ./a.out > log.txt $ ```
You could usetee: ``` $ ./a.out | tee log.txt ```
The below program redirects all my output to log file. I need to display all the output along with log file. How can this be achieved? ``` $ gcc test.c $ ./a.out > log.txt $ ```
You could usetee: ``` $ ./a.out | tee log.txt ```
Is it possible to develop applications for Roku inCorC++as the SDK is written inC? If yes, how? If no, then which languages other thanBrightscriptcan apps be developed in?
My understanding is yes, at least with games and the Marmalade SDKhttps://www.roku.com/developer. I actually just downloaded the SDK and have not looked at it in much detail yet, but as it seems, developing for Roku involves a mix of Brightscript, C++ and Java (Android). Hope that helps!
In Unix, C. After afork(), usually followed by await()orwaitpid()to wait thechildterminate. But can thechildexecute thewait()? Thechilddoesn't have a_child_, so when it execute thewait(), what will happen?
There are no child proccess for the child proces sowait()will return -1. From the man page: wait(): on success, returns the process ID of the terminated child; on error, -1 is returned.
I have a very simple macro for which I want to typecast its output tointonly. How to do that? ``` #define Numbits(A) (sizeof(A)*CHAR_BIT) ``` I tried: ``` #define int Numbits(A)({int val; val = sizeof(A)*CHAR_BIT; return val;}) ``` but it also doesn't work
Are you saying that#define Numbits(A) (int)(sizeof(A)*CHAR_BIT)didn't work?
If I have program with a main thread and a function running in a separated detached thread. If something in the detached thread is returning something > 0 will only the child thread exit or the main thread too?
A Posix thread returnsvoid *(ie. a pointer), so it cannot return anything less than zero since it's not an integer. In any case, the return value from a detached thread is always ignored, and the process will not exit whatever the value.
Doesalignof(N) == sizeof(N)where N is an integral type? I'm asking for both C and C++, hope this isn't a problem.
It's machine-specific. On a 32-bit machine,alignof(int64_t)could easily be 4. Too, assumptions that are widespread now won't be for so very long.
Doesalignof(N) == sizeof(N)where N is an integral type? I'm asking for both C and C++, hope this isn't a problem.
It's machine-specific. On a 32-bit machine,alignof(int64_t)could easily be 4. Too, assumptions that are widespread now won't be for so very long.
What combination of preorder,inorder and postorder Traversal generate a unique binary Tree?
following combination can uniquely identify a tree. Inorder and Preorder. Inorder and Postorder. Inorder and Level-order. And following do not. Postorder and Preorder. Preorder and Level-order. Postorder and Level-order. For more infomation refer:Geeksforgeek
This question already has answers here:size of int variable(6 answers)Closed4 years ago. Why in Turbo C compilersizeof(int)is 2 bytes and in gcc Linux compiler is of 4 bytes?
sizeof(int)is not a constant across all platforms. It varies from system to system. PS: Only sizeof object which is constant across all platforms issizeof(char)
I am looking for the clang equivalent of the cl command /FC. I need full paths for my build tool to parse out and open the code files with the errors. https://msdn.microsoft.com/en-us/library/027c4t2s.aspx
CFLAGS+= -fdiagnostics-absolute-paths
I've asorted arraybut it'snot necessarily sequential, and I need to knowIF it contains any duplicates. ``` Array : | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 8 | 8 | ``` I know we can linearly traverse in O(n) check if it contains any duplicates, but I was wondering if it is possible using Binary Search.
No, You can't do it with binary search. All algorithms will take at least linear time.
I am looking for the clang equivalent of the cl command /FC. I need full paths for my build tool to parse out and open the code files with the errors. https://msdn.microsoft.com/en-us/library/027c4t2s.aspx
CFLAGS+= -fdiagnostics-absolute-paths
The code excerpt: ``` int main(int argc, char *argv[]){ PySys_SetArgv(argc, argv); ``` produces error message error: cannot convert ‘char**’ to ‘wchar_t**’ for argument ‘2’ to ‘void PySys_SetArgv(int, wchar_t**)’ How do I convertargv?
You could look into whether your compiler supportswmain. If so, you can replacemainwith: ``` int wmain(int argc, wchar_t *argv[]) { PySys_SetArgv(argc, argv); ```
I am trying to convert from arduino to avr-c. I get the errorSREGis undeclared. Do you know whatSREGis?.
SREGis theStatusRegister. It is#define'd in one of the AVR headers, so you are probably missing an#include(perhapsavr/io.horavr/common.h).
As per my knowledge range of unsigned char in C is 0-255. but when I executed the below code its printing the 256 as output. How this is possible? I have got this code from "test your C skill" book which say char size is one byte. ``` main() { unsigned char i = 0x80; printf("\n %d",i << 1); } ```
Because the operands to<<*undergointeger promotion. It's effectively equivalent to(int)i << 1. * This is true for most operators in C.
As per my knowledge range of unsigned char in C is 0-255. but when I executed the below code its printing the 256 as output. How this is possible? I have got this code from "test your C skill" book which say char size is one byte. ``` main() { unsigned char i = 0x80; printf("\n %d",i << 1); } ```
Because the operands to<<*undergointeger promotion. It's effectively equivalent to(int)i << 1. * This is true for most operators in C.
If file is opened using fopen() and in different mode then is it necessary to close it number of time or it can be closed once at end of code ?
Each time you open the file, you are going to receive different file descriptors or file handles. So you have to close each file handle usingfclose()if opened viafopen()orclose()if opened viaopen().
I saw someone doing this to have array index starting at 1 instead of 0 in C. ``` a = (int *) malloc(sizeof(int)*3) - 1 ``` Is there any risk in this?
Theoretical risk : only null pointers and pointers to, into, or right after an object are valid. Other pointers trigger undefined behaviour on use (if they're dangling) or when creating them through pointer arithmetic. Practical risk : getting pelted by a random code reviewer.
I saw someone doing this to have array index starting at 1 instead of 0 in C. ``` a = (int *) malloc(sizeof(int)*3) - 1 ``` Is there any risk in this?
Theoretical risk : only null pointers and pointers to, into, or right after an object are valid. Other pointers trigger undefined behaviour on use (if they're dangling) or when creating them through pointer arithmetic. Practical risk : getting pelted by a random code reviewer.
If for example I usedLoadImage()to load a bitmap from file in Thread A, can I use the returnedHBITMAPin Thread B?
Yes you can, but remember a bitmap can only be selected into one DC at once. If you have two threads both drawing the same bitmap you'll need to coordinate access to it.
For example: when I round a float into an int, why should I use : int i = (int) round(f); Instead of : int i = int round(f);
What is the difference between int and (int) in C? anintis the built-in type integer and(int)isType Casting.
``` Min Profile Cycles [215914] Max Profile Cycles [934625] Max Profile [23] Max Profile Count [4] ``` How to print all these console output into some .txt file in c so that whenever i will call that function it will print in txt file instead of printing in console.
as your tag is C, you can fopen() in append-mode a file and instead of using printf() you use fprintf() (and fwrite() and similar) with this filehandle.