question
stringlengths
24
425
answer
stringlengths
5
405
I'm using a dsPic33F (16 bit microcontroller); How to convertchar[]toint[]such that every two chars becomes an int using C++?and the inverse operation?
``` int* intArray = new int[sizeOfByteArray]; for (int i=0; i<sizeOfByteArray; ++i) intArray[i] = byteArray[i]; ``` Or ``` std::copy(byteArray, byteArray+sizeofByteArray, intArray); ```
Using C or a bat file, I'm trying to edit the file hosts file from c:\Windows\System32\drivers\etc but I can;t bc it is write protected. Can you tell me what can i do?
The program modifying the host file needs to run as Administrator
``` #include<unistd.h> int main(int argc, char **argv) { int ret; ret = execve("/bin/bash", NULL, NULL); return 0; } ``` i m confuse about why the null values are passsed in execve please help.....
Those parameters correspond to the program's arguments and environment. By passing NULL in for both, the caller is indicating that no arguments should be supplied to the program and no environment variables should be supplied either.
This question already has answers here:Closed12 years ago. Possible Duplicate:Why there is not a comprehensive c archive network? Like Python has a Cheeseshop and Perl has CPAN? Google results have a lot of C++ results and I am looking for purely C libraries. PS: Looking for *nix libraries
Yep. SourceForge, Codeplex, Github, and Google. Also, your distro's packages, if you are on Linux.
As the title implies: the scenario is a coder with a gdb and a user reporting a crash. Can he get from the user an easy to use memory dump which can be fed to gdb but also not make it hard for the user?
You can set upProcess Dumperto produce a full dump on any exception or process exit, based on the name of the executable file. I am assuming Windows due to the title, alter the tags if not.
I am trying to store every hex value from 0000 to fffe into a file. How would I use fwrite or fprintf to place these values into a file? At the moment, I have a while loop that prints all the numbers using printf (which is to the console screen), but I need them in a file.
``` fprintf(fp, "%04x", your_number) ```
Does Google protocol buffers are binary-compatibly with C structures? I mean can I read serialized files from C direct into structs without deserializing? Orprotobuf-cis the only one solution?
Depending on the alignment, endianness and packing of structures on your platform, this may or may not work. You may be lucky with your particular target, but in general you should use proper serialise / deserialise routines.
As the title implies: the scenario is a coder with a gdb and a user reporting a crash. Can he get from the user an easy to use memory dump which can be fed to gdb but also not make it hard for the user?
You can set upProcess Dumperto produce a full dump on any exception or process exit, based on the name of the executable file. I am assuming Windows due to the title, alter the tags if not.
I am trying to store every hex value from 0000 to fffe into a file. How would I use fwrite or fprintf to place these values into a file? At the moment, I have a while loop that prints all the numbers using printf (which is to the console screen), but I need them in a file.
``` fprintf(fp, "%04x", your_number) ```
Does Google protocol buffers are binary-compatibly with C structures? I mean can I read serialized files from C direct into structs without deserializing? Orprotobuf-cis the only one solution?
Depending on the alignment, endianness and packing of structures on your platform, this may or may not work. You may be lucky with your particular target, but in general you should use proper serialise / deserialise routines.
I wanted to know what is the current standard C compiler being used by companies. I know of the following compilers and don't understand which one to use for learning purposes. Turbo CBorland CGCCDJGPP I am learning C right now and referring to the K&R book. Can anyone please guide me to which compiler to use?
GCCwould be the standard, best supported and fastest open source compiler used by most (sane) people.
I have a header file for a game that declares a two-dimensional array for a board. ``` #ifndef GAME_H_ #define GAME_H_ static const int columns = 15; static const int rows = 15; int board[rows][columns]; #endif /* GAME_H_ */ ``` I get an error: error: variably modified 'board' at file scope
C doesn't allowconstvariables as array bounds. Use an enum instead: ``` enum { columns = 15, rows = 15 }; ```
Example: ``` var x, y, z; //... x > 100 ? y = x : z = x ; ```
Yes it does work the same although operator precedence is always tricky so I would recommend parenthesis to avoid confusion. tangentially related..You can also use||in JavaScript similar to the null coalescing operator??in C#
I wanted to know what is the current standard C compiler being used by companies. I know of the following compilers and don't understand which one to use for learning purposes. Turbo CBorland CGCCDJGPP I am learning C right now and referring to the K&R book. Can anyone please guide me to which compiler to use?
GCCwould be the standard, best supported and fastest open source compiler used by most (sane) people.
I have a header file for a game that declares a two-dimensional array for a board. ``` #ifndef GAME_H_ #define GAME_H_ static const int columns = 15; static const int rows = 15; int board[rows][columns]; #endif /* GAME_H_ */ ``` I get an error: error: variably modified 'board' at file scope
C doesn't allowconstvariables as array bounds. Use an enum instead: ``` enum { columns = 15, rows = 15 }; ```
Example: ``` var x, y, z; //... x > 100 ? y = x : z = x ; ```
Yes it does work the same although operator precedence is always tricky so I would recommend parenthesis to avoid confusion. tangentially related..You can also use||in JavaScript similar to the null coalescing operator??in C#
For jpeg,gif,png I use libgd. ( not ImageMagick - it's not possible ). May I resize bmp image using simple method/library ?
Most of the libraries that deal with image resizing represent the image as a bitmap (i.e. an uncompressed array of pixels) internally. So it wouldn't be very hard to read in a bitmap image from a file and put it in memory.
quick question Can you use the free() function without having to prior call a malloc ?? ei. ``` void someFunc( void ) { char str[6] = {"Hello"}; //some processing here .... free(str); } ``` I get no compiling errors but Does this work or is it correct at all ? Thank you,
This is not at all correct: You cannot free a static array such aschar str[6].free() should only be called on memory you allocated (or on NULL).
I could find a C++ onehere, but no pure C one. Any pointers?
C code for a red and black tree, licensed with the very generousMIT license. (Backup at archive.org.)
I have a file with various 'return BBQ;' statements. I'd like to change them all to 'exit(BBQ);\nreturn BBQ;' (with BBQ being an arbitrary value). Is this possible?
Backreferences. ``` s/return \(BBQ\);/exit(\1);\nreturn \1;/ ```
Somebody can give me an example to do this. Suppose static variable scope is limited to file only.That is private to that file.Like that some more examples i want to know. In other words HOW TO ACHIEVE DATA HIDING CONCEPT IN C-LANGUAGE WITH CURRENTLY AVAILABLE KEYWORDS(STRUCT,STATIC...ETC)
This guy is one of the worlds authorities on embedded systems. He wrote this white paper on OOP in c. http://www.state-machine.com/resources/cplus_3.0_manual.pdf
quick question Can you use the free() function without having to prior call a malloc ?? ei. ``` void someFunc( void ) { char str[6] = {"Hello"}; //some processing here .... free(str); } ``` I get no compiling errors but Does this work or is it correct at all ? Thank you,
This is not at all correct: You cannot free a static array such aschar str[6].free() should only be called on memory you allocated (or on NULL).
So I need to get web camera fps rate in OpenCV. Which function can do such thing for?
``` int cvGetCaptureProperty( CvCapture* capture, int property_id); ``` withproperty_id = CV_CAP_PROP_FPS
I have two bytes, 8 bit octets, which should be read as: [3 bits][4 bits][3 bits]. Example: ``` unsigned char octet1 = 0b11111111; // binary values unsigned char octet2 = 0b00000011; ``` As integers: [7][15][7]. Anybody can give me a hint where to start?
In a kind ofpseudocode ``` octet1 = 0b11111111 octet2 = 0b00000011 word = octet1 | octet2<<8 n1 = word & 0b111 n2 = word>>3 & 0b1111 n3 = word>>7 & 0b111 ```
I have two bytes, 8 bit octets, which should be read as: [3 bits][4 bits][3 bits]. Example: ``` unsigned char octet1 = 0b11111111; // binary values unsigned char octet2 = 0b00000011; ``` As integers: [7][15][7]. Anybody can give me a hint where to start?
In a kind ofpseudocode ``` octet1 = 0b11111111 octet2 = 0b00000011 word = octet1 | octet2<<8 n1 = word & 0b111 n2 = word>>3 & 0b1111 n3 = word>>7 & 0b111 ```
I use the Tiny C Compiler and I want to useGetUserNamefrom the WinAPI. My problem is, I don't know how to link toadvapi32.dll I get an error from tcc: ``` undefined symbol '_GetUserNameA@8' ```
I explained how to create a .def file from a dll and how to compile and link with tcc here:Tiny C Compiler (TCC) and winsock?
``` #include<stdio.h> void compute(int); int cube(int); int main( ) { compute(3); } void compute(int in) { int res=0,i; for(i=1;i<=in;i++); { res=cube(i); printf("%d %d",res,i); } } int cube(int n) { return (n*n*n); } ``` ~output : 64 4 How does it happen ?
Semicolon at the end of yourforline.
in php ``` $arr = array() $arr[0] = "string 1"; $arr[1] = "string 2"; ``` how about in c? thanks
You need to declare an array of pointers. Each element of the array is a pointer to the string. You need to copy the string in, and then release it when done. ``` char *strings[2]; strings[0] = strdup("Hello, world!"); printf("%s\n", strings[0]); free(strings[0]); ```
For example: ``` console> please enter 3 digits: 1 2 3 ``` I only know how to accept 1 digit usingscanf: ``` scanf("%d", &space); ```
You can read in multiple numbers with scanf ``` int a, b, c; scanf("%d %d %d", &a, &b, &c); ```
I've been going through some C source code and I noticed the following: ``` void some_func (char *foo, struct bar *baz) { (void)foo; (void)baz; } ``` Why isvoidused here? I know(void)before an expression explicitly indicates that the value isthrown away; but can someone please explain me the rationale for such an use?
This code ensures that you won't get a compiler warning about foo and baz being unused.
``` int SDL_BlitSurface(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect); ``` Why are the srcrect and dstrect arguments not const? Are they modified in the function? At the moment I'm const-casting my Sprite class member variables to use BlitSurface... It seems silly.
Becausethey're modified.
What is a good C compiler for OSX or Windows XP or DOS? I would like to make a GUI shell for DOS. Also what is a good pascal compiler for these platforms?
On Mac OS X, you should use the GNU Compiler Collection (GCC). You can install it by downloading and installing the freeXcode Developer Tools. On Windows, you can also install GCC (usingCygwin).
I have this code in C: ``` int main(){ char a[10]; _asm{ mov DWORD PTR[a],eax;} ``` This works well, but why do I actually need the ``` DWORD PTR ``` When the DWORD size is already stated by using eax? IAnd for destination, I dont need any size whe I have pointer, right? Thanks.
It is because your code is wrong. Theavariable is an array, not a pointer. Declare it char* and you don't need the override. The code is nonsense of course.
How to convert lower case ASCII char into upper case using a bitmask (no -32 allowed)? I'm not asking for solving my homework, only some hints. Thanks
As you state "(no -32 allowed)", I guess you know that the difference between lower case characters and upper case characters is 32. Now convert 32 to its binary representation, there's only one bit set. After that, work out a way to use abit maskto switch the bit.
I have an integer matrix that should act like a buffer: x = {{0, 0, 0, 0, 0}, {1, 1, 1, 1, 1}, {2, 2, 2, 2, 2}}; Now if I add a new row{3, 3, 3, 3, 3}, the new matrix should look like: x = {{1, 1, 1, 1, 1}, {2, 2, 2, 2, 2}, {3, 3, 3, 3, 3}}; Is there a clever way of doing this without copying all elements around?
If your matrix is defined as anint **and you separately allocate each row, then you would only have to swap the row pointers.
I have a C file generated with f2c (Fortran to C translator) that contains the following C structure: ``` struct { real rez, pi, st; } const_; ``` How can I declare thisconst_variable as an external in another .c file without modifying the one generated by f2c?
In another file. ``` extern struct { real rez, pi, st; } const_; ```
Given strings like the following: ``` sdfsd34 sdfdsf1 ``` I would like to extract:34, 1using c++ (STL but no boost), c. thanks
You’re searching for the functionstring.find_last_not_of: ``` string str = "sdfsd34"; size_t last_index = str.find_last_not_of("0123456789"); string result = str.substr(last_index + 1); ```
Can I use a socket library from TCC? I can't find any reference to winsock or sys/socket.h in the include directory. If i remember correctly, winsock was part of the windows platform SDK (?) If so can I link that with TCC?
According toTinycc-devel mailing list you should give this a try: ``` tiny_impdef winsock.dll -o winsock.def tcc yourcode.c winsock.def -o yourcode.exe ```
I want to call a function of the business class after every 2 hours. I m not getting any way to implement same in C/C++ without using a while loop. My problem is that i cannot use while(1) as this does not retun back the control for further execution. Any pointer in this regards wud be helpful....:) thnaks
Boost.AsioprovidesTimers.
with other IDE, you can pass parameter to the program via the IDE (it save times instead of typing hello.c parameter1 parameter2 in the shell) Is there any way to pass parameters to the program trhough the Xcode IDE instead of just clicking on "RUN" then "CONSOLE" (which provide no arguments to the program) Thanks
Under "Executables" get info on your binary. Go to the "Arguments" tab, and add them there.
I want to create a route server to proxy some clients(they may not in the same intranet) to access internet. I need to assign unique ip to the client and get the ip when packets response,so I can do some monitor task. i want to know if I use PPPoE server to deal with this case, how to through NAT ? thanks!
You can't. NAT routes packets in theTransport layer, but PPPoE operates in theData Link layer; NAT can't evenseePPPoE packets.
When you see code like this in C, what's the order of assignment? ``` int i = 0, var1, var2; ``` I don't understand the syntax...
Onlyiis assigned the value zero. var1andvar2are uninitialized.
I am playing withlibnetfilter_queueand am looking for a good C library to work with packets captured by libnetfilter_queue. I really like thedpktlibrary for python and some similar library for C would be wonderful. Any other workaround or example code for manipulating the packets are also welcome. with regards, raj
Netfilter's TPROXY target is available (even at *BSD) => setsockopt can be done from your python code without messing at C.
Why are function arguments pushed on the stack in right to left order?
To enable the existence of functions with a variable number of arguments, like printf. The function can extract the first one or two arguments and then use their values to deduce the total number of arguments on the stack.
I am playing withlibnetfilter_queueand am looking for a good C library to work with packets captured by libnetfilter_queue. I really like thedpktlibrary for python and some similar library for C would be wonderful. Any other workaround or example code for manipulating the packets are also welcome. with regards, raj
Netfilter's TPROXY target is available (even at *BSD) => setsockopt can be done from your python code without messing at C.
Why are function arguments pushed on the stack in right to left order?
To enable the existence of functions with a variable number of arguments, like printf. The function can extract the first one or two arguments and then use their values to deduce the total number of arguments on the stack.
scanf("%s",str) won't do it. It will stop reading at the first space. gets(str) doesn't work either when the string is large. Any ideas?
usefgetswith STDIN as the file stream. Then you can specify the amount of data you want to read and where to put it.
``` const struct sockaddr FAR* name, ```
It's an old extension from the era of segmented memory architectures. It basically means "this is a pointer that needs to be able to point at any address, not just things in the same segment as the code using it". See more or on thewikipedia page.
There are many good packages for calculating the intersection of polygons. I have found the GPC library useful. I would like to compute intersections of polyhedra (piecewise linear boundaries) in 3D. Are there any good libraries in C/C++ for this?
So far, I've foundCGAL, but I haven't tried it out yet.
Can we anyhow change the size of the pointer from 2 bytes so it can occupy more than 2 bytes?
Sure, compile for a 32 (or 64) bit platform :-) The size of pointers is platform specific, it would be 2 bytes only on 16-bit platforms (which have not been widely used for more than a decade - nowadays all mainstream[update](desktop / laptop / server)[/update]platforms are at least 32 bits).
The question is&str[2], if I writestr+2then it would give the address and its logical but where did I used pointer notation in it? Should I prefer writing&(*(str+2))?
You can use either ``` &str[2] ``` or ``` (str + 2) ``` Both of these are equivalent.
what does this sybol means please? "<<" for example: if (1 << var) I want the name of the thing to study. Thank you.
It shifts the bits in the integer 1varpositions to the left. So in effect it calculates 2 to the power ofvar. Seethe article on bit shifts on wikipedia.
I am working on a C assignment for uni, and I've been coding in TextMate and compiling in the command line. But TextMate wont (or cant) format C code, as it would for say, HTML, Ruby or PHP (using SHIFT + CTRL + F). Is there a plugin or some other tool I can use to fix my indenting and curly braces for .c files?
I useastyle. It has a lot of options to customize according to your coding style, and I think it is included in the major linux distributions.
For instance if I called WriteFile to the end of a file, and later I wanted to delete the written bytes, how could I do this? Do I have to read the file's contents into a buffer, re-create the file, and write the desired bytes, or is there an easier way?
Seekto the file position you want to truncate from (if you're not already there), then call the aptly-namedSetEndOfFile()function.
Is there a way to set the blending parameters so the whole scene renders in grayscale? (without using GLSL, only pipeline functions) Thanks
No, all colors are separated. You need a pixel shader for that
I need to use natural cubic spline interpolation in an iPhone app. Does anyone know of a class for Obj C or C that resembles this:http://www.ee.ucl.ac.uk/~mflanaga/java/CubicSpline.html "performing an interpolation within a one dimensional array of data points, y = f(x), using a cubic spline."
Look at thisarticleThis is a sample for Curve Fitting. It uses Cubic Spline Interpolation, and Bezier Spline Curve.
I have a C source file having comments in//(C++) style. I want to change all the comments to the old/* */(C) style. Is there a way to do this using an existing script?
A substitution with you favorite editor and a regular expression likes#//(.*)#/*\1 */#should do it...
How do I cause a thread to respond topthread_cancel()if it is blocked on asem_wait()?
You can set a signal handler, let's says for SIGUSR1, for the thread that will be blocking then, from another thread, you callpthread_cancel(tid)andpthread_kill(tid, SIGUSR1). The thread will be canceled oncesem_wait()is interrupted by the signal.
Many times I see in open source code that a call to a C function is cast to void. For example, in the source code forls(http://cvs.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/cmd/ls/ls.c) I see the following. ``` (void) setlocale(LC_ALL, ""); ``` Why is this good practice?
It explicitly means you ignore the return value, and did not just forget it.
I am looking for a automated finite state machine generator for C? I have seen a few over the internet but unable to decide which one to use. If anybody worked with any such tool then help me to find the right one. Thanks, Ravi Gupta
Ragelis fairly powerful.
I'm Interested in writing gedit-plugins in C. I've checkedGedit/NewMDIPluginHowTo...but haven't had any luck with it. How can I get more information about writing gedit plugins in C?
If you're willing to use Python instead,hereis a tutorial for writing gedit plugins in Python.
I have#include<math.h>, and I tried to use pow(x, y) and powf(x, y). but it seems neither of them are under c99 standard. and I use the commandgcc -std=c99 test.c -o testto compile. what function there exists I can use?
Forhistericalreasons, the math library is not bundled in with the rest of the Standard Library. You have to manually add it to the compilation with the-lmoption to gcc. ``` gcc -std=c99 test.c -o test -lm ```
I am looking for a automated finite state machine generator for C? I have seen a few over the internet but unable to decide which one to use. If anybody worked with any such tool then help me to find the right one. Thanks, Ravi Gupta
Ragelis fairly powerful.
I'm Interested in writing gedit-plugins in C. I've checkedGedit/NewMDIPluginHowTo...but haven't had any luck with it. How can I get more information about writing gedit plugins in C?
If you're willing to use Python instead,hereis a tutorial for writing gedit plugins in Python.
I have#include<math.h>, and I tried to use pow(x, y) and powf(x, y). but it seems neither of them are under c99 standard. and I use the commandgcc -std=c99 test.c -o testto compile. what function there exists I can use?
Forhistericalreasons, the math library is not bundled in with the rest of the Standard Library. You have to manually add it to the compilation with the-lmoption to gcc. ``` gcc -std=c99 test.c -o test -lm ```
I've downloaded Eclipse C/C++ IDE . I need to run a simple c program in this(To print welcome). While trying to run the program its popping up an error message like"Launch failed: Binary not found" . Need i install any compiler package. ? Please help me to do this.
Yes, you have to install a compiler, Eclipse is only an IDE. You can get MinGWhere.
This question already has answers here:Closed12 years ago. Possible Duplicate:What does a colon in a struct declaration mean, such as :1, :7, :16, or :32? This is C code sample of a reference page. ``` signed int _exponent:8; ``` What's the meaning of the colon before '8' and '8' itself?
It's a bitfield. It's only valid in astructdefinition, and it means that the system will only use 8 bits for your integer.
I was trying to develop a chat application using C programmable sockets. I need to check whether the stdin buffer has some value in it to send the message to the client/server and receive it. But I don't know how to check the stdin buffer for values. Please help.
You wantselect(2,3p).
``` struct stats { char top : 1; char bottom : 1; char side : 2; } MyStat; ``` I have seen this format with integers but how does the above char bit field work and what does it represent? Thank You.
Char bit fields work in the same way as int, just the base type is 8-bit wide, not 32-bit. So you'd get a struct stats, which has the size of 1 byte, and 3 member variables, occupying a total of 4 bits.
``` struct stats { char top : 1; char bottom : 1; char side : 2; } MyStat; ``` I have seen this format with integers but how does the above char bit field work and what does it represent? Thank You.
Char bit fields work in the same way as int, just the base type is 8-bit wide, not 32-bit. So you'd get a struct stats, which has the size of 1 byte, and 3 member variables, occupying a total of 4 bits.
there is someone that know if exist a XSD code generator for C source code? I have a lot of xsd files and I need to generate C struct and relative function fromXml and toXml. Thanks.
For C++ generation there ishttp://sourceforge.net/projects/xxsd2code/
This post is edited and the original post here is asking the implementation of _malloc_r which is not a good move to use. My question now is there any other malloc implementation or alternative function for malloc and free functions? Please advice. Many thanks.
Give up on trying to have a reentrantmalloc. It's a bad idea. If you really need to allocate memory from signal handlers, usemmap, but even that is a bad design.
I have an array of double (size more than 60k entries), I have the frequency value. Now I want to create a sound from it using C/C++ which I can play on speaker. My OS is linux. Thanks. I hope I am clear enough.
http://www.linuxjournal.com/article/6735 This is a link to an article in Linux Journal about programming with the ALSA (Advance Linux Sound Architecture). It contains some example code.
Do these two structs have the same memory layout? (C++) ``` struct A { int x; char y; double z; }; struct B { A a; }; ``` Further can I access x, y, z members if I manually cast an object of this to anA? ``` struct C { A a; int b; }; ``` Thanks in advance. EDIT: What if they wereclassesinstead ofstructs?
Yes and yes. The latter is commonly used for emulating OO inheritance in C.
Is it possible to get the list of #defines(both compile time and defined in the source code) used in a C program while execution. Because i am having a project having lot of C source files. Is there any compile time option to get that?
GNUcpptakes various-doptions to output macro and define data. See their man pages for more details.
This question already has answers here:Closed12 years ago. Possible Duplicate:C# driver development? Why do we use C for device driver development rather than C#?
Because C# programs cannot run in kernel mode (Ring 0).
I have an array of double (size more than 60k entries), I have the frequency value. Now I want to create a sound from it using C/C++ which I can play on speaker. My OS is linux. Thanks. I hope I am clear enough.
http://www.linuxjournal.com/article/6735 This is a link to an article in Linux Journal about programming with the ALSA (Advance Linux Sound Architecture). It contains some example code.
Do these two structs have the same memory layout? (C++) ``` struct A { int x; char y; double z; }; struct B { A a; }; ``` Further can I access x, y, z members if I manually cast an object of this to anA? ``` struct C { A a; int b; }; ``` Thanks in advance. EDIT: What if they wereclassesinstead ofstructs?
Yes and yes. The latter is commonly used for emulating OO inheritance in C.
Is it possible to get the list of #defines(both compile time and defined in the source code) used in a C program while execution. Because i am having a project having lot of C source files. Is there any compile time option to get that?
GNUcpptakes various-doptions to output macro and define data. See their man pages for more details.
This question already has answers here:Closed12 years ago. Possible Duplicate:C# driver development? Why do we use C for device driver development rather than C#?
Because C# programs cannot run in kernel mode (Ring 0).
How many different ways are there to define constants in C or C++? I am already aware of using theconstkeyword and the#definedirective. I heard somewhere that there are two more ways to define constants, but I've never seen any others. Are there any others?
enum, as inenum { some_constant= 2 }; EDIT: I also forgot the additions ofconstexprand user defined literals in the C++0x standard. So there are actually three additional ways.
Let's say I have this line of code in a program: ``` int * number=0; int mystery=&6[number]; ``` Mistery is a number and I can use &5 or &4 obtaining other numbers. But what does the "&6[]" mean? Thanks!
6[number]is exactly equivalent tonumber[6], so you're getting the address that's six integers away fromnumber. Since number is0and anintis 4 bytes long, the result is24.
What must this code segment return ? 16 16 16 right ? ``` int main(int argc,char *argv[]) { int a=2,*f1,*f2; f1=f2=&a; *f2+=*f1+=a+=2.5; printf("%d %d %d\n",a,*f1,*f2); return 0; } ``` strangely, it returns 8 8 8 to me ???? :-(
For an actual understanding of the issue here trycomp.lang.c FAQarticle onsequence points.
I always find that some people (a majority from India) are using turbo C. I cannot find any reason to use such outdated compiler... But I don't know what reasons to give when trying to tell them to use modern compiler(gcc,msvc,...).
Turbo C is a DOS only product. This means that it no longer runs "natively" on 64-bit versions of Windows, and must be run inside the XP compatibility penalty box.
I have a string in the following format: "R: 625.5m E:-32768m" What's the most efficient way to pull out the 625.5?
Your best bet is to usesscanfto read formatted information from the string. ``` sscanf(mystr, "R: %f", &myFloat); ```
I always find that some people (a majority from India) are using turbo C. I cannot find any reason to use such outdated compiler... But I don't know what reasons to give when trying to tell them to use modern compiler(gcc,msvc,...).
Turbo C is a DOS only product. This means that it no longer runs "natively" on 64-bit versions of Windows, and must be run inside the XP compatibility penalty box.
I have a string in the following format: "R: 625.5m E:-32768m" What's the most efficient way to pull out the 625.5?
Your best bet is to usesscanfto read formatted information from the string. ``` sscanf(mystr, "R: %f", &myFloat); ```
Is there an easy way to request that a GTK widget have a minimum width/height? I know you can do it on the column of aTreeView, but is it available for general widgets?
For C/C++:gtk_widget_set_size_request() Sets the minimum size of a widget; that is, the widget's size request will be width by height. PyGTK:def set_size_request(width, height)
I'm not even sure what sliding average is, but someone told me it would help with something I'm working on. I have a table of random values --table[n] = random(100) / 100 I need to populatetable2with their sliding averages. I think this is the terminology. Let me know if it doesn't make sense.
TheMoving averageentry on Wikipedia might be a good start.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened,visit the help center.Closed11 years ago. Can I work with Begali charachters(non ASCII) in C?
Absolutely. Look into libiconv or ICU.
How to read command line inputs using a C program.by command line inputs, I don't mean command line arguments!! example: * I have a text file 'inputfile.txt' with few lines of names.* Assume my program name is names.exe.* I have to run the program using windows command line using following command:c:>names.exe < inputfile.txt Thanks.
Read from thestdinFILE*.
This function definition is found here.: ``` static void (*resolve_memcpy (void)) (void) { return my_memcpy; // we'll just always select this routine } ``` I don't understand what it means.
resolve_memcpy is a function taking no arguments and returning a pointer to a function taking no arguments and returning void. EDIT: Here's a link where you can read more about this kind of syntax:http://unixwiz.net/techtips/reading-cdecl.html
As the title says, I always wonder whyscanfmust take theaddress ofoperator (&).
Because C only has "pass-by-value" parameters, so to pass a 'variable' to put a value into, you have to pass its address (or a pointer to the variable).
There are 2 servers, they need to know the status(live oe dead) each other. my method is a long tcp connecting, Is there any better method? thanks.
I`m no sysadmin, but why not simply use nmap or the likes to check if the ports your servers are listening on are still open? I mean, you simply want to know if they are alive or dead, right? When one of your server crashes, the port shouldn´t be open anymore.
Can you please point me to library(ies) for face detection (NO RECOGNITION NEEDED!)? Any good-working libraries except OpenCV(!!!). Preferably free of charge - open source is not required.
What bothers you about OpenCV? Their API or something else? There islibfacewhich is an opencv wrapper for face detection and recognition.
Why the range of signed character is-128to127but not-127to128?
That is because of the waytwo's complementencoding works: 0 is treated as a "positive" number (signed bit off), so, therefore, the number of available positive values is reduced by one. Inones' complementencoding (which is not very common nowadays, but in the olden days, it was), there were separate values for +0 and -0, and so the range for an 8-bit quantity is -127 to +127.
The C99 standard describes them as so: The integer and real floating types are collectively called real types.Integer and floating types are collectively called arithmetic types. Does this mean they're the same thing in C? Or are there any differences between them?
Complex types are arithmetic types, but not real types.
I was wandering how could capture video from the built-in camera of my netbook, under Linux, ubuntu. The programming language could is not an issue (but I prefer Java or the old school c) Thanks in advance for your answers, Gian
You can look into OpenCV, for C/C++. It is very powerful.
I want to add a C file into my .NET application. How can I built this? How can i write unmanaged code in C#. Can someone explain with few lines code. Thanks
You either have to build the C file into it's own DLL and thenuse P/Invokein your C# code to call them or... You could also try to port the C code to C# which would give you a completely managed codebase.
I want to add a C file into my .NET application. How can I built this? How can i write unmanaged code in C#. Can someone explain with few lines code. Thanks
You either have to build the C file into it's own DLL and thenuse P/Invokein your C# code to call them or... You could also try to port the C code to C# which would give you a completely managed codebase.