question
stringlengths
24
425
answer
stringlengths
5
405
Does the standard Cctimefunction return the Gregorian calendar date? In particular, I want to verify that it will account for leap years and thus displayFeb 29for the respective dates.
For times in the future and in the recent past, yes. For times before the Gregorian calendar reform... I don’t know, but those times are only relevant on systems with 64 bittime_t.
can somebody explain these answers? I can understand 2. , 4. but the rest i can not ``` int a[ ] ={2,4,3,1,10,5,9,6,8,7}; int *pa = &a[4],*pb = &a[1]; What is the value of the below? 1.*(a + 3) 2.*pb-*pa 3.pb[3] 4.*pa + 5 5.*(pa-2) 6.pa[4] Answer: 1.*(a + 3)=1 2.*pb-*pa=-6 3.pb[3]=10 4.*pa + 5=15 5.*(pa-2)=3 6.pa[4]=8 ```
x[y]is equivalent toy[x], which is equivalent to*(x+y)or*(y+x). So*(a+3)is equivalent toa[3]or3[a].
Trying to compile in win7 x64 cmd prompt. The following command: ``` nvcc -o kernal.cu ``` yields the following error message. ``` nvcc : fatal error : No input files specified; use option --help for more information ```
try nvcc -o xxx kernal.cu where xxx is the output file name you want.
When linking a static library as athin archivethe .o-files are not copied into the archive, but rather they are referenced with their relative path from the .a file. How can I check if a given .a file is a thin archive or not?
How can I check if a given .a file is a thin archive or not? ``` head -1 t.a !<thin> ``` Eventually,file(1)should be able to tell you. Myfile-5.09just saysdata.
When linking a static library as athin archivethe .o-files are not copied into the archive, but rather they are referenced with their relative path from the .a file. How can I check if a given .a file is a thin archive or not?
How can I check if a given .a file is a thin archive or not? ``` head -1 t.a !<thin> ``` Eventually,file(1)should be able to tell you. Myfile-5.09just saysdata.
I've encountered the following line in a .cuh file: ``` #define mp_ptr(n) P##n ``` What does theP##npart mean?
It means concatenation. It's a C preprocessor directive. So,mp_ptr(1)becomesP1,mp_ptr("foobar")becomesP"foobar", etc.
I have the following code: ``` typedef struct { int a; float b; int c; } Hello; Hello hello[100]; ``` I know I can assign value to the first element of this array: ``` hello[0] = {1,2.0,3}; ``` but how to assign the first element when we declare thehello: Hello hello[100];
Requires additional set of{}(outer{}for the array, inner set(s) for the elements of the array): ``` Hello hello[100] = { {1, 2.0, 3} }; ```
I've encountered the following line in a .cuh file: ``` #define mp_ptr(n) P##n ``` What does theP##npart mean?
It means concatenation. It's a C preprocessor directive. So,mp_ptr(1)becomesP1,mp_ptr("foobar")becomesP"foobar", etc.
I'm using visual studio to write a c code. This is the malloc code line i was told to use: ``` root = (Coor)malloc(sizeof(Coor)); ``` It doesn't let me use it for the following error: ``` identifier not found ``` Can anyone tell me why it happens and how to fix it? Thanks,
Please check if you have included<stdlib.h>and<malloc.h>.
I want to implementing my own system call. (See below link) http://www.tldp.org/HOWTO/html_single/Implement-Sys-Call-Linux-2.6-i386/ But adding new system call requires kernel compilation. How to implement my own system call without recompiling the Linux kernel?
You can't. Without recompiling the kernel, all you can do is build and load kernel modules, and kernel modules cannot add new system calls.
For wcscmp() and wcscoll() are wide-character comparison. What is differences ?
Thewcscollwill interpret the parameters as appropriate to theLC_COLLATEcategory of the current locale. If local is not an issure,wcscmpfunctions should be used, especially with large wstrings for performance.
I have 8 uint32 elements and i want to break each uint32 into 4 uint8 then add all uint8 beside each others as unsigned chars in the array , how can i do that ?
You can make use of the power ofunionfor this ``` union value { uint32 number; struct bytes { uint8 bytevalue[4]; }; }; ```
For wcscmp() and wcscoll() are wide-character comparison. What is differences ?
Thewcscollwill interpret the parameters as appropriate to theLC_COLLATEcategory of the current locale. If local is not an issure,wcscmpfunctions should be used, especially with large wstrings for performance.
I would like to synchronize folders and files between a server and some client. Due to the fact that the client part is limited by firewalls and proxy server, I'm forced to use a HTTP based solution. Is there any HTTP/REST based library (both server and client side) optimized for file synchronization? (Python or C based solutions would be nice.) PS: the server side has to run on linux
You could tryWebDAV Python hassome librariesto handle it
This question already has answers here:Forcing GCC to compile .cpp file as C(2 answers)Closed10 years ago. I have a C++ project [IDE = codelite] which tries to compile .c extention using g++ I want to specify a flag for .c file so that g++ treats it as c What is the g++ command line option to make it behave as gcc ?
Either ``` gcc file.c ``` or ``` g++ -x c file.c ``` will do what you want...
Is there a convenient library call that allows me to open the default browser that I can use from C? I poked around in glib and didn't see anything. There is xdg-open, and I can just system that I guess. Any better ideas?
Since you tagged this question with "glib", the right solution is probably to useg_app_info_launch_default_for_uri(or one of the other GAppInfo methods, depending on your exact use case).
I need to create user timer and thread in windows kernel program. Anyone please give a clue that if the regular threading headers are applicable in this mode?
You need to look into KMDF or WDM if you are using some old drivers. For timers see this: http://msdn.microsoft.com/en-us/library/windows/hardware/ff550050(v=vs.85).aspx And here are threads or work items: http://msdn.microsoft.com/en-us/library/windows/hardware/ff551203(v=vs.85).aspx
I need to create user timer and thread in windows kernel program. Anyone please give a clue that if the regular threading headers are applicable in this mode?
You need to look into KMDF or WDM if you are using some old drivers. For timers see this: http://msdn.microsoft.com/en-us/library/windows/hardware/ff550050(v=vs.85).aspx And here are threads or work items: http://msdn.microsoft.com/en-us/library/windows/hardware/ff551203(v=vs.85).aspx
How I can make a file unexecutable in winapi ?Something like quarantine in anti-viruses .Is it possible or not ?Thanks a lot .
If you overwrite the first two bytes of the file with something other than MZ it won't be recognised as an executable file any more.
How I can make a file unexecutable in winapi ?Something like quarantine in anti-viruses .Is it possible or not ?Thanks a lot .
If you overwrite the first two bytes of the file with something other than MZ it won't be recognised as an executable file any more.
Standard C utility librarystdlib.hhas these function names: (String as 'a'): atofatoiitoa (String as 'str'): strtoulstrtolstrtod Why is a string sometimes called an "a" and sometimes called an "str"?
astands forASCII, so in atoi it isASCIIto integer.See here. Theatofamily of functions have been deprecated bystrfunctions.
I want to create a program like gdb or gnuplot that has it's own command prompt. I'm looking for a library that will handle the parsing/input validation as well as provide a command history. So far googling for this topic is difficult because any search with the terms 'c' and 'shell' will only produce results for 'csh'.
History is usually managed byreadlineorlibedit. Parsing is usually done withflex/bison.
came across this and was wondering what it does ``` LPCTSTR szmyLPCTSTR; // doing _tcsncpy things with that string //at the end then there is this line which i am not sure what it does szmyLPCTSTR[122] = 0; ``` Thanks !!
LPCTSTR is simply a pointer to characters. It's adding a null terminator to the string.
I am trying to figure out how to use this. I'm way out of my element here, so thanks for bearing with me.
Libgit2 works primarily on repositories that you have disk access to, meaning you have to clone the repository before you can use libgit2 to work with it. Once you've got that, you'll get a handle to your repository usinggit_repository_open, and create the branch usinggit_branch_create.
What's wrong in my function 'front'? I want to pass the pointer to an specific line in my array to read/edit it. ``` struct queue { char itens[LN][CL]; int front,rear; }; char *front(struct queue * pq) { return pq->itens[pq->front+1][0]; } ```
You're currently returning a singlechar, not a pointer to a row. Take off the[0]: ``` char *front(struct queue *pq) { return pq->itens[pq->front+1]; } ```
Where can I find the implementation of if_nametoindex? It seems to be externed in net/if.h but searching through the source code I cannot find any hint on the implementation. A better question is, how would I find what library it is defined in etc...
You can try to search through all projects, not just apple sources:http://code.metager.de/source/s?&sort=relevancy&defs=if_nametoindex&reset=trueTake a look atfreebsd implementationfor example.
Eclipse popped a new one on me this morning. See the circled icon in the image. I have looked at lots of links from similar posts on SO (though didnt find any for thsi exact icon) and none of the links have mentioned this. FYI this is in Texas Instruments Code Composer Eclipse "package", or however it's termed, but searching over at TI has been just as fruitless.
It means this folder is in a workspace path.
Is there a way to to something like: ``` char* a = "Hello"; char* b = NULL; char* c = a | b; Result should be c = "Hello"; ``` Seems like it does not work with Char*, but is there a way to do something like that?
This is nonsense not only because bitwise operators on pointers would have very... interesting... results, but mainly becauseNULL is not guaranteed to be represented by 0.
Is there a way to to something like: ``` char* a = "Hello"; char* b = NULL; char* c = a | b; Result should be c = "Hello"; ``` Seems like it does not work with Char*, but is there a way to do something like that?
This is nonsense not only because bitwise operators on pointers would have very... interesting... results, but mainly becauseNULL is not guaranteed to be represented by 0.
When we do not give the value in a macro substitution. ``` #define YES printf("%d",YES) ``` The value of YES is not given, is it by default 0 or garbage?
You just defined YES tonothing. So the result program after preprocessor should beprintf("%d",)
When we do not give the value in a macro substitution. ``` #define YES printf("%d",YES) ``` The value of YES is not given, is it by default 0 or garbage?
You just defined YES tonothing. So the result program after preprocessor should beprintf("%d",)
Am I using scanf() in some wrong way? ``` char *input; scanf("%s", input); printf("%s\n", input); ``` This fails at the run-time.
Declaring achar *only creates a pointer, it does not allocate any memory for the string. You need to allocate memory for input. You can do that dynamically viamalloc(andfreewhen done) or you can declare an array of static size likechar input[100].
In a makefile, what is the difference in meaning betweenincludeand-include? Examples: ``` -include $(APPINCLUDES) include $(CONTIKI)/platform/$(TARGET)/Makefile.$(TARGET) ```
The difference is that-includewon't generate an error if the include file doesn't exist. The-prefix can be used many places in theMakefileto perform actions that you don't mind if they fail.
Is it to check for the WS_CHILD bit: ``` LONG style = GetWindowLong(hwnd, GWL_STYLE); int isTopLevel = !(style & WS_CHILD); ``` Or is there a better way? Assume: Straight C calling only existing Windows API code.
Way #1: TesthWnd==GetAncestor(hWnd,GA_ROOT)Way #2: UseIsTopLevelWindow(user32 Win7, undocumented)
Is there a macro to return (ideally as aconst char*or indeedcont char *const) the typename of its parameter or some information on it? This is atcompile time, not runtime, so C++'s typeinfo will not do. I run with-fno-rttianyway.
There isn't. C++11 does have the__func__identifier inside function definitions, which produces a string variable with the function name. Most C++ compilers have variations on this to have "decorated" function names.
I am using Eclipse IDE on ubuntu to code in C. I use its normal debugging and default compiler ( GCC ) am writing code with OpenMP features. Eclipse just skips the pragmas and compiles the code in serial. So I end up running the program from terminal with the -fopenmp parameters. I was wondering if there is a way to make eclipse compile and debug the OpenMP parts as well ?
You need to go toBuild > Settings > Miscellaneous > All optionsand add-fopenmp.
Is there a macro to return (ideally as aconst char*or indeedcont char *const) the typename of its parameter or some information on it? This is atcompile time, not runtime, so C++'s typeinfo will not do. I run with-fno-rttianyway.
There isn't. C++11 does have the__func__identifier inside function definitions, which produces a string variable with the function name. Most C++ compilers have variations on this to have "decorated" function names.
I am using Eclipse IDE on ubuntu to code in C. I use its normal debugging and default compiler ( GCC ) am writing code with OpenMP features. Eclipse just skips the pragmas and compiles the code in serial. So I end up running the program from terminal with the -fopenmp parameters. I was wondering if there is a way to make eclipse compile and debug the OpenMP parts as well ?
You need to go toBuild > Settings > Miscellaneous > All optionsand add-fopenmp.
I want to detect the kill signal of my program inorder to execute some C instruction before leaving my program. my program is running on linux Is it possible to do that? If yes how I can do it?
You can register asignal handlerusingsigaction(). Note that you cannot handleSIGKILLorSIGSTOPthough.
Where is _TRACE macro defined? What's the purpose of it? Does it trace the stack and lets you know when your app crash?
If you want you can define it compile time using below command ``` make CFLAGS=-D_TRACE ```
How do I represent extremely large or small numbers in C with a certain amount of significant figures. For example, if I want to do calculations on 1.54334E-34, how could I do this. Also, is this applicable to OpenCL code?
``` float var = 1.54334E-34; double var2 = 1.54334E-34; printf("\n normal:%f\n sci:%e \n or \n sci:%E \n",var,var,var); printf("\n normal:%f\n sci:%e \n or \n sci:%E \n",var2,var2* 1.0E3 ,var2 * 1.0e3); ```
I am looking at taking the 10 bit data from my ADC conversion and storing it into 1 16 bit integer data looks like 0x03 ADRESH 0xFF ADRESL. What I am doing right now is ``` data = 0x03 & ADRESH; data = data << 8; data = data & 0x03FF & ADRESL; ``` will this work how I think it should or am I missing something? thanks for the help
Why don't you use the|operator ?short data = ((0x03 & ADRESH) << 8) | ADRESL;should work fine.
How to memcpy the two dimensional array in C: I have a two dimensional array: ``` int a[100][100]; int c[10][10]; ``` I want to usememcpyto copy the all the values in array c to array a, how to do this using memcpy? ``` int i; for(i = 0; i<10; i++) { memcpy(&a[i][10], c, sizeof(c)); } ``` is this correct?
That should work : ``` int i; for(i = 0; i<10; i++) { memcpy(&a[i], &c[i], sizeof(c[0])); } ```
I was experimenting withwchar_tand I tried to copy one array into another array. here is my code: ``` wchar_t name[]=L"Aayman Khalid"; wchar_t Name[50]=L""; wcscpy_s(Name,sizeof(name),name); printf_s( "Name = %s\n", Name ); ``` however when I run this code,I get the first letter i.eA. could someone explain to me as to why that is? Also how could I get the full name copied?
Useprintf_swith"%ls"specifier.
Where is _TRACE macro defined? What's the purpose of it? Does it trace the stack and lets you know when your app crash?
If you want you can define it compile time using below command ``` make CFLAGS=-D_TRACE ```
How do I represent extremely large or small numbers in C with a certain amount of significant figures. For example, if I want to do calculations on 1.54334E-34, how could I do this. Also, is this applicable to OpenCL code?
``` float var = 1.54334E-34; double var2 = 1.54334E-34; printf("\n normal:%f\n sci:%e \n or \n sci:%E \n",var,var,var); printf("\n normal:%f\n sci:%e \n or \n sci:%E \n",var2,var2* 1.0E3 ,var2 * 1.0e3); ```
I am looking at taking the 10 bit data from my ADC conversion and storing it into 1 16 bit integer data looks like 0x03 ADRESH 0xFF ADRESL. What I am doing right now is ``` data = 0x03 & ADRESH; data = data << 8; data = data & 0x03FF & ADRESL; ``` will this work how I think it should or am I missing something? thanks for the help
Why don't you use the|operator ?short data = ((0x03 & ADRESH) << 8) | ADRESL;should work fine.
How to memcpy the two dimensional array in C: I have a two dimensional array: ``` int a[100][100]; int c[10][10]; ``` I want to usememcpyto copy the all the values in array c to array a, how to do this using memcpy? ``` int i; for(i = 0; i<10; i++) { memcpy(&a[i][10], c, sizeof(c)); } ``` is this correct?
That should work : ``` int i; for(i = 0; i<10; i++) { memcpy(&a[i], &c[i], sizeof(c[0])); } ```
I was experimenting withwchar_tand I tried to copy one array into another array. here is my code: ``` wchar_t name[]=L"Aayman Khalid"; wchar_t Name[50]=L""; wcscpy_s(Name,sizeof(name),name); printf_s( "Name = %s\n", Name ); ``` however when I run this code,I get the first letter i.eA. could someone explain to me as to why that is? Also how could I get the full name copied?
Useprintf_swith"%ls"specifier.
recvfrom on IPv6 sockets (GNU/Linux) gives unusual addresses for the client/from address of the forma00::<two_radom_bytes>:</64_network_prefix>. What are theses addresses called or by what search terms can more information be found?
Finally found the problem staring right at me; I used&addrinstead of&addr.sin6_addrfor function inet_ntop. Sorry for bugging everyone with this silly problem.
``` char p[3][6]={{'a','b','c','\0'},{'d','e','f','\0'},{'g','h','i','\0'}}; char s[3][6]={"abc","def","ghi"}; ``` Are they both same? If different please explain what way and how it is stored in memory?
They're the same in memory. Here in the VS 2010 debugger, I cast to char* so I can inspect the first 18 raw bytes of p and s:
i wrote a program in C using Dev-Cpp, my question is : how can i change and customize this program icon ?
The program will default to the lowest-numbered icon in its resources. (If you don't have a resource script yet then you need to add one to your project.)
I have this piece of code in C: ``` void f(void *x) { printf(">>> %p\n", x); } int main() { f NULL; return 0; } ``` I think is for the definition of NULL, but I'd like an explanation to clarify my doubt.
IfNULLis defined as((void *)0)or(0), then this expands tof ((void *)0)orf (0), which are proper function calls. The code errors out for anything non-parenthesized during compilation.
I have foundSetupDiGetDeviceRegistryPropertyto get properties from devices, but I havent figured out how to get the parent property (you can see this property when you open a devices properties in device manager, click on details, and choose parent from the property drop down. How do I access that property from native c++ code?
The predefined DEVPKEY_Device_Parent guid is the key for the Parent property. Read it with SetupDiGetDeviceInterfaceProperty().
I have foundSetupDiGetDeviceRegistryPropertyto get properties from devices, but I havent figured out how to get the parent property (you can see this property when you open a devices properties in device manager, click on details, and choose parent from the property drop down. How do I access that property from native c++ code?
The predefined DEVPKEY_Device_Parent guid is the key for the Parent property. Read it with SetupDiGetDeviceInterfaceProperty().
I want an equivalent forprintf("%2.2x", var);tocerr<<in C++.code: ``` typedef unsigned char byte; static byte var[10]; for(i=1; i<10; i++) printf("%2.2x", var[i]); ``` The idea is to redirect the debugging to a file like this:./myprog 2>out.txt.If I don't ask too much I would like to receive explanations too.Thanks!
Usefprintf(stderr, ...), e.g.: ``` fprintf(stderr, "%2.2x", var[i]); ```
I installed a windows service with cygwin cygrunsrv. That service is writing something to a file every 5 seconds. After I tried it, I removed service with "cygrunserv -R service_name". Now, service is removed from services list but it is still running. How can I remove it for real.
Restarting Windows is solving that issue.
I just can't find an algorithm to split the string into words by numerous delimiters. I know how to split a string by whitespace withistringtreamand bysingle delimiterwithgetline. How can I connect them all. For instance: input:This -is-a!,string;output: ``` This is a string ```
Why not just#include <cstring>and usestd::strtok()in your C++ program?
I installed a windows service with cygwin cygrunsrv. That service is writing something to a file every 5 seconds. After I tried it, I removed service with "cygrunserv -R service_name". Now, service is removed from services list but it is still running. How can I remove it for real.
Restarting Windows is solving that issue.
I just can't find an algorithm to split the string into words by numerous delimiters. I know how to split a string by whitespace withistringtreamand bysingle delimiterwithgetline. How can I connect them all. For instance: input:This -is-a!,string;output: ``` This is a string ```
Why not just#include <cstring>and usestd::strtok()in your C++ program?
I just can't find an algorithm to split the string into words by numerous delimiters. I know how to split a string by whitespace withistringtreamand bysingle delimiterwithgetline. How can I connect them all. For instance: input:This -is-a!,string;output: ``` This is a string ```
Why not just#include <cstring>and usestd::strtok()in your C++ program?
What would be an alternative for Microsoft C++ compiler's#importdirective in a C (notC++) source code? Are there any tools which automatically produce C interfaces from a given type library?
The closest I know is using the OLE/COM object viewer (OLEVIEW.EXE) to get part of the IDL back, correcting a few missing things, and then running that through MIDL again.
Is it possible to write a message on assert error? For example, using#include <assert.h>, I can only write: ``` void foo(int a, int b) { assert (a != b); } ``` However, on an error I want to see the value ofaandb. How can I do that?
I usually simply useassert(a != b && "This is my error message"). This works becausechar*can be converted to bool and that it never will be false (since the address is not 0).
What would be an alternative for Microsoft C++ compiler's#importdirective in a C (notC++) source code? Are there any tools which automatically produce C interfaces from a given type library?
The closest I know is using the OLE/COM object viewer (OLEVIEW.EXE) to get part of the IDL back, correcting a few missing things, and then running that through MIDL again.
Is it possible to write a message on assert error? For example, using#include <assert.h>, I can only write: ``` void foo(int a, int b) { assert (a != b); } ``` However, on an error I want to see the value ofaandb. How can I do that?
I usually simply useassert(a != b && "This is my error message"). This works becausechar*can be converted to bool and that it never will be false (since the address is not 0).
I want to know if there is a way to read date from console in format dd.mm.yyyy in C. I have a structure with information for the date. I tried with another structure just for the date with day, month and year in it: ``` typedef struct { int day; int month; int year; } Date; ``` but the dots are a problem. Any idea?
Try: ``` Date d; if (scanf("%d.%d.%d", &d.day, &d.month, &d.year) != 3) error(); ```
Considering the following definition: ``` struct { int x; int y; } point; void main() { ... } ``` You're declaring the variable "point" of "anonymous struct" type, is there any way to declare another variable of the same type outside the struct definition (maybe in main function)?
No, there isn't, at least not in standard C. If you want to use the type, you have to give it a name.
I want to get the IP address of the client who’s just connected into my server running WinSock2. I’m using C.
You could get the client's IP-address and port via the call toaccept(). Just pass in the appropriate data into the last two parameters. ``` struct sockaddr_in sa = {0}; /* for TCP/IP */ socklen_t socklen = sizeof sa; ... = accept(..., (struct sockaddr *) &sa, &socklen); ``` For detailsplease read here.
I am studying the FAT32 manual, now i want to write a program to browse the device. How to read a specific sector of the device, i do not want to load the entire device as a file into memory, please suggest some system call's to get started.
Find the block device in/dev/, then your system calls areopen,lseek, andread. Higher level stuff likefopen,fseek, andfreadwill work too.Everything is a file.
I am studying the FAT32 manual, now i want to write a program to browse the device. How to read a specific sector of the device, i do not want to load the entire device as a file into memory, please suggest some system call's to get started.
Find the block device in/dev/, then your system calls areopen,lseek, andread. Higher level stuff likefopen,fseek, andfreadwill work too.Everything is a file.
This question already has answers here:Accessing arrays by index[array] in C and C++(2 answers)Closed10 years ago. I am dealing pointers in c and when i run the following code i get "l" as the output! Why? ``` char *s = "Hello, World!"; printf("%c", 2[s]); ``` What does 2[s] signify?
2[s]is same ass[2]because compiler convert both into*(2 + s) here is a good link for you:why are both index[array] and array[index] valid in C?
The PIC is a16F630 ``` #FUSES NOWDT, INTRC_IO, PROTECT, NOBROWNOUT, MCLR, CPD, NOPUT #use delay(clock=4000000) #use fast_io(A) ``` later, in a function: ``` #asm nop nop nop nop nop #endasm ``` Which C compiler could have been used to compile this code?
Looks like theCCS PIC MCU C compiler. As you can see at the link its pre-processor supports#FUSES,#USE,#ASMand#ENDASM.
What's the simplest way to copy the unix file permissions of a file and set them to another file? Is there a way to store a file's permissions to a variable and then use that variable to set those permissions to another file?
Sure. Usestat()andchmod()(may need root). ``` #include <sys/stat.h> struct stat st; stat("/foo/bar.txt", &st); chmod("/baz/quirk.jpg", st.st_mode); ```
In Dennis Ritchie I found this, ``` struct rect r , *rp = r; ``` then these four expressions are equivalent : r.pt1.xrp->pt1.x(r.pt1).x(rp->pt1).x because operators associate left to right.Shouldn't it be struct rect *rp = &r?
Absolutely -- the address operator is required,otherwise you get a compile-time error: ``` incompatible types when initializing type ‘struct rect *’ using type ‘struct rect’ ```
Is it possible to check which db2 code page is used in communication between ODBC connector and db2 database from c program using ODBC api?
It's indicated by the connection attribute SQL_ATTR_CLIENT_CODEPAGE. Here's the function to obtain it:SQLGetConnectAttr
What does a number argument inprintfwithout quotes do? e.g.printf( 3 + "goodbye");results in output dbye. Why do I get this output?
3 + "goodbye"is equivalent to&"goodbye"[3]- in other words it's just a pointer to the fourth element of "goodbye" and so your example will print "dbye".
What does a number argument inprintfwithout quotes do? e.g.printf( 3 + "goodbye");results in output dbye. Why do I get this output?
3 + "goodbye"is equivalent to&"goodbye"[3]- in other words it's just a pointer to the fourth element of "goodbye" and so your example will print "dbye".
What does a number argument inprintfwithout quotes do? e.g.printf( 3 + "goodbye");results in output dbye. Why do I get this output?
3 + "goodbye"is equivalent to&"goodbye"[3]- in other words it's just a pointer to the fourth element of "goodbye" and so your example will print "dbye".
In all of the gtk examples I've read, callbacks are always static functions. I think I remember reading somewhere that there is a reason for that, but I can't find it now. Must GTK callback functions be static? How come? What would go wrong if I defined them in a different control unit?
No. Nothing bad will happen if you make your callback functions not static.
``` printf("Hello%cWorld\n", '\r'); ``` Outputs: ``` World ``` Because'\r'moves the cursor to the beginning of the line Can I trust that all terminals have this behavior?
lib curses will tell you the capabilities of your terminal.
``` printf("Hello%cWorld\n", '\r'); ``` Outputs: ``` World ``` Because'\r'moves the cursor to the beginning of the line Can I trust that all terminals have this behavior?
lib curses will tell you the capabilities of your terminal.
Is there any C function to check if string s2 exists in s1? s1: "CN1 CN2 CN3" s2: "CN2" or "CG2" s1 is fixed, and I want to check whether variants of s2 exists in s1 or not. I am using C not C++.
You can usestrstr: ``` #include <string.h> if (strstr(s1, s2) != NULL) { // s2 exists in s1 } ```
This question already has answers here:What does an assignment return?(5 answers)Closed4 years ago. In the following code: ``` int c; while((c=10)>0) ``` What doesc = 10evaluate to? Is it 1 which indicates that the value 10 is assigned to variable c successfully, or is it 10? Why?
c = 10 is an expression returning 10 which also assigns 10 to c.
I tried ``` printf("%s %15s", string1, string2); ``` and I found out that this kind of left padding depends the distance from the first string, what if I want an absolute left padding counting from the left most?
You want to pad the first string on the right, instead of padding the second sting on the left: ``` printf("%-15s %s",string1,string2); ```
the assert() function can print the error and where the error happens, but it will also abort the function. I want to have a assert() function without aborting. I only hope to print the error, the name of the file where error happens, etc. is there such a API or source snippets in C? thanks!
Cunit has an assert that will either be fatal (quits) or not (will continue). http://cunit.sourceforge.net/doc/writing_tests.html#tests
Is there a stable and portable way to make use of PostGIS-functions in my own PostgreSQL extension? I would like to process the geometry type with functions like intersects in my c code by directly calling this functions from the postgis-$version.so (in PostgreSQL's $libdir).
You should generally do this by invoking the SQL-level PostGIS functions via either theSPIor viafmgrfast-path calls. Seethis related question about using hstore from C.
I'm making a wrapper for a C library. There is a method that changes 2 ints by the user giving 2 int pointers to the method. So if I havevoid changenums(int* a, int* b)what is a safe way to access this method in c#?
Declare the p/invoke like this: ``` [DllImport(@"mydll.dll")] static extern void changenums(ref int a, ref int b); ``` And call it like this: ``` int a = 0; int b = 0; changenums(ref a, ref b); ```
I'm making a wrapper for a C library. There is a method that changes 2 ints by the user giving 2 int pointers to the method. So if I havevoid changenums(int* a, int* b)what is a safe way to access this method in c#?
Declare the p/invoke like this: ``` [DllImport(@"mydll.dll")] static extern void changenums(ref int a, ref int b); ``` And call it like this: ``` int a = 0; int b = 0; changenums(ref a, ref b); ```
I'm making a wrapper for a C library. There is a method that changes 2 ints by the user giving 2 int pointers to the method. So if I havevoid changenums(int* a, int* b)what is a safe way to access this method in c#?
Declare the p/invoke like this: ``` [DllImport(@"mydll.dll")] static extern void changenums(ref int a, ref int b); ``` And call it like this: ``` int a = 0; int b = 0; changenums(ref a, ref b); ```
Simple code, eg: ``` void* print_my_address() { printf("%p\n", .../* get the execution address of print_my_address */) } ``` Thanks! PS: gcc v4.7 Can I get the address by compiler?
The same way you'd do it for any other regular variable: ``` void print_my_address() { printf("%p\n", &print_my_address); } ```
char label[10] = "Me"works, and to change the value oflabel, I'd have to do something like: ``` char * temp = "Not Me"; strcpy(label,temp); ``` My question is why is this invalid? ``` char label[] = "Me"; label = "Not me"; ```
Because arrays are not assignable. You can create them, you can change theircontent, but the array itself cannot be modified to refer to a new chunk of memory.
I am running a C program using DEVC++ and CodeBlocks in Windows and the code is not updating. I just added a single printf message and it is not shown in the output. I tried clean,rebuild,recompile, everything. Please tell me what's going wrong.
Try adding a newline to your printf. Sometimes (with certain compilers), the output isn't flushed to screen until a newline is printed. ``` printf( "\n" ); ```
I need to make a function using just~and|, such that functionf(6, 5)will return4as the answer.
By De Morgan's law,~(a | b)equals~a & ~b. By the same law,a & bequals~(~a | ~b).
I need to make a function using just~and|, such that functionf(6, 5)will return4as the answer.
By De Morgan's law,~(a | b)equals~a & ~b. By the same law,a & bequals~(~a | ~b).
I have a simple Opengl programm where I draw triangles by calling glVertex3f and the mode GL_LINE_LOOP here's what I get: You can see in the square that apparently some triangles that are at the base of my model (in blue) are drawn above what is in the foreground. Do you know what is causing it? Is there a way to avoid it?
gluPerspective(60., Width/Height,0,1000); The near-z cannot be 0 or less. It must be a positive number greater than zero.
I am working with eclipse, jni, c, CentOS6. I really want to see some logs from C code, but in eclipse console, it does not show printf Message which happens in C. Is there any way to print C logs in eclipse console?
@Ozan Deniz Thanks for sharing your knowledges. to summarize that link, eclipse has C console problem itself. so if someone print C msg in eclipse console, has to use fprintf(stderr, "")... Thanks again.
I am working with eclipse, jni, c, CentOS6. I really want to see some logs from C code, but in eclipse console, it does not show printf Message which happens in C. Is there any way to print C logs in eclipse console?
@Ozan Deniz Thanks for sharing your knowledges. to summarize that link, eclipse has C console problem itself. so if someone print C msg in eclipse console, has to use fprintf(stderr, "")... Thanks again.
I have not been able to find any information with a web-search. Where should I be looking?
``` char myString[256]; // Input string char dest[256]; // Destination string strncpy(dest, myString, 10); dest[10] = 0; // null terminate destination ```
ARCforbidsObjective-Cobjects instructs orunions. Unless you add__unsafe_unretainedwhich means its not managed. I was wonder what people are using in place ofstructs now if anything? Or are you retaining everything manually?
It's very simple - if you want to add an object inside a struct, you are doing it wrong. Whenever you need a struct to hold an obj-c object, convert the struct into an obj-c object.
(UNIX) I have 2 programs in C in which I use a named pipe (created by mkpipe, fopen etc.) to communicate. There is one writer and multiple readers for that pipe. Is there any way to set a maximum possible number of readers, in writer's code?
No there is no such way to do that.