question
stringlengths
24
425
answer
stringlengths
5
405
I am new to writing programs in c++ and i want to know if there is a way to export it to a windows format. Also what is a good way to learn objective-c, is it very different from c++? Thank you in advance.
Using mingw32 you can cross compile for windows. Seehttp://www.mingw.org/wiki/LinuxCrossMinGW
If I do*ptr[x], is that equivalent to*(ptr[x]), or(*ptr)[x]?
*(ptr[x]) See theWikipedia operator precedence table, or, for a more detailed table,this C/C++ specific table.
What is the difference between C & C# on the basis of OOP concepts?
The difference is in the support of those OOP concepts. C does not support OOP concepts while C# does.
I have binary array in c, I want to compress the array, kindly suggest me algorithm which compress binary array. I have used Lempel–Ziv–Welch (LZW) algorithm but its not suitable for me because there is no repetition in my data.
Why not just to use thelibz'sdeflate? As added bonus, libz is available on pretty much every existing platform. Or newerLZMA? It beats thebzip2on binary data compression.
I have binary array in c, I want to compress the array, kindly suggest me algorithm which compress binary array. I have used Lempel–Ziv–Welch (LZW) algorithm but its not suitable for me because there is no repetition in my data.
Why not just to use thelibz'sdeflate? As added bonus, libz is available on pretty much every existing platform. Or newerLZMA? It beats thebzip2on binary data compression.
I have binary array in c, I want to compress the array, kindly suggest me algorithm which compress binary array. I have used Lempel–Ziv–Welch (LZW) algorithm but its not suitable for me because there is no repetition in my data.
Why not just to use thelibz'sdeflate? As added bonus, libz is available on pretty much every existing platform. Or newerLZMA? It beats thebzip2on binary data compression.
What does the code(10%2)mean?
%is themodulusoperator. So this essentially says - what is the remainder of 10 divided by 2? ``` 10 % 2 == 0 10 % 5 == 0 10 % 7 == 3 10 % 3 == 1 ```
I need to print this value as a time string to Mon 16-Aug-2010 06:24 format or something similar. ``` unsigned int t = 1281920090; ```
You can use the functionsgmtimeandasctimeas: ``` #include <stdio.h> #include <time.h> int main() { time_t timestamp = 1281920090; printf("%s", asctime(gmtime(&timestamp))); return 0; } ``` Output: ``` $ gcc a.c && ./a.out Mon Aug 16 00:54:50 2010 ```
Hallo, I'm looking for a really simple and easily hackable tar library for C or C++. Ideally it should have a permissive license (BSD/LGPL) and not have a ton of Unix/Windows OS dependencies, as I plan to use it from an embedded RTOS... Any ideas?
I haven't used it myself, but have you triedlibtar? It is written in C and BSD licensed.
Is there a built in function to convert ints to Big-endian or little-endian for sending over the network? like htonl and ntohl in c Also, is there something similar to strings, datetime, etc.. Thanks
Java streams use network byte order. That means you only have to worry about things likehtonlandntohlin C and it ilk.
how does a call from c++ to c work internally??
The C++ compiler 'does the right thing' and uses the correct calling convention for the C function - a lame sounding answer but I don't know that there's much more that can be said!
In applications like Adobe Illustrator, they have a way to simplify a path. I'm not sure how this works exactly. Given a path with points which have 2 bezier handles each (for cubic bezier), how could I go about simplifying the path? Thanks
Look atDouglas–Peuckerit is an algorithm for reducing the number of points in a curve that is approximated by a series of points. It is frequently used in GIS solutions.
hello i got a problem with returning an array of linklists in c lets say i got arrlinklist = {linklist1 , linklist 2...,linklist5} and i want my function to return arrlinklist. how do i do that... thx in advance. i wanted to know how to define the signature of my function i tried linkedlist* CreateArrayOfList();
In C you cannot return an array, you can only return a pointer to the first element of the array.
im porting c code to windows 32 bit using visual studio expressnow i have 3 functions that i can't find any alternatives in windowsthey are:alarmbzerobcopywhat are the equivalent methods in C win32 ?
alarm you are going to need to dig for the other two are: ``` #define bzero(b,len) (memset((b), '\0', (len)), (void) 0) #define bcopy(b1,b2,len) (memmove((b2), (b1), (len)), (void) 0) ```
It's been awhile since I've played with c, and now I find something I've never seen before: ``` printf("%-16llu", my_var); ``` It would seem to be saying print 16 characters of a long unsigned int. But, what's the second 'l' for? long long?
``` %llu ``` Is forunsigned long long. This was added in C99 (and much, much after K&R wrote the book).
In GTK I can't figure out what callback to setup so that when the user clicks in a window, I can get the X/Y co-ords of the click.
You're looking for thebutton-press-eventsignal ofGtkWidget.
It's been awhile since I've played with c, and now I find something I've never seen before: ``` printf("%-16llu", my_var); ``` It would seem to be saying print 16 characters of a long unsigned int. But, what's the second 'l' for? long long?
``` %llu ``` Is forunsigned long long. This was added in C99 (and much, much after K&R wrote the book).
In GTK I can't figure out what callback to setup so that when the user clicks in a window, I can get the X/Y co-ords of the click.
You're looking for thebutton-press-eventsignal ofGtkWidget.
My friends tell me that a special loop exists that isn't a 'while' loop or a 'do while' loop. Does anyone know what it's called and the correct syntax for it's use?
A for loop maybe? ``` for (i = 0; i < 15; ++i) { /* do stuff */ } ```
GCC is normally instructed to output to a file via the-oswitch. If this isn't provided it seems to decide on an appropriate name and output to that. How do I make GCC write its generated output to stdout?
``` gcc -o /dev/stdout foo.c ``` Note that/dev/stdoutis defined as a symlink:/dev/stdout -> /proc/self/fd/1.
The question was asked to me in an interview and my answer was "computer memory". But where exactly..? is it the Random Access Memory or the hard drive?
They were probably looking for "the heap". This is an area of memory that's separate from "the stack", which is where all your local variables, parameters, return values, etc., are stored. And yes, it's all in RAM, not on the hard drive.
I have a number of private frameworks I want to use, however I cannot find any headers for them. Is there a de-facto way of getting arguments fromCfunction calls usingIDA Pro? (NotObjCmessages). Edit: Oops, I meantCnotC++.
Access r0-r3 and the stack pointer?
I am new to using the PARI C library. How can I perform bitwise ('and' or 'or') operations on the GEN type variables?
usinggbitandandgbitor? Declared inarith2.cseethis link(sorry for the not so direct link): ``` GEN gbitand(GEN x, GEN y) GEN gbitor(GEN x, GEN y) ```
just wanted to know how to call php script from running C code on Linux and pass a couple of parameters. Thanks
``` system("/usr/bin/php /path/to/program.php param1 param2"); ```
I would like to know why spin locks are used instead of semaphores inside an interrupt handler.
Semaphores cause tasks to sleep on contention, which is unacceptable for interrupt handlers. Basically, for such a short and fast task (interrupt handling) the work carried out by the semaphore is overkill. Also, spinlocks can't be held by more than one task.
I am porting a large project to Windows, and I'm stuck on unistd.h. I doubt this code is using a great deal of unistd's functionality, so I think I could be able to provide some sort of replacements for it. Meanwhile, I need to figure out what features of the header the code is using. Is there any tool that will tell you what features of a header are being used?
Comment #include "unistd.h" lines. See everything that is not compiled. As requested :)
Why would you ever want to use alloca() when you could always allocate a fixed size buffer on the stack large enough to fit all uses? This is not a rhetorical question...
It could be useful if the size of the buffer varies at runtime, or if you only sometimes need it: this would use less stack space overall than a fixed-size buffer in each call. Particularly if the function is high up the stack or recursive.
I am porting a large project to Windows, and I'm stuck on unistd.h. I doubt this code is using a great deal of unistd's functionality, so I think I could be able to provide some sort of replacements for it. Meanwhile, I need to figure out what features of the header the code is using. Is there any tool that will tell you what features of a header are being used?
Comment #include "unistd.h" lines. See everything that is not compiled. As requested :)
I need to store a value between 0-15 in C , 4 bits are enough for this. How can I just have a variable of 4 bits? Space is a constraint here
Consider using achar. Yeah, it's 8-bits, but you can use the bit shift operators (<<and>>) to store values in the other 4 bits. Edit:Per the comments below, anunsigned charis, in fact, preferable overcharto avoid issues with the sign bit.
I need to store a value between 0-15 in C , 4 bits are enough for this. How can I just have a variable of 4 bits? Space is a constraint here
Consider using achar. Yeah, it's 8-bits, but you can use the bit shift operators (<<and>>) to store values in the other 4 bits. Edit:Per the comments below, anunsigned charis, in fact, preferable overcharto avoid issues with the sign bit.
I need to store a value between 0-15 in C , 4 bits are enough for this. How can I just have a variable of 4 bits? Space is a constraint here
Consider using achar. Yeah, it's 8-bits, but you can use the bit shift operators (<<and>>) to store values in the other 4 bits. Edit:Per the comments below, anunsigned charis, in fact, preferable overcharto avoid issues with the sign bit.
I have looked at some resources to tell me how->and.are different, but they seem to do the same thing. Does->act like a dot operator on a struct?
.is used when you have a struct, and->is used when you have a pointer to a struct. The arrow is a short form for dereferencing the pointer and then using.:p->fieldis the same as(*p).field.
This question already has answers here:float to int unexpected behaviour(6 answers)Closed6 years ago. What will be the behavior and output of the following code if i accidentally code so in C/C++, ``` float a = 12.5; printf("%d\n", a); printf("%d\n", *(int *)&a); ```
Rubish and more rubish. You would get something meaningful if you did the following though ``` printf("%d\n", (int)a); ```
In OSX, I'm used to simply doing ``` ./configure make ``` But in MSVC when I do Project from existing code and try to compile I get hundreds of errors. I'm trying to compile GLU from the Mesa3D library. How could I do this in MSVC? Thanks
Still fighting with glu ? :) In windows\VC8\mesa you have a .sln. Find it, open it, compile it, done.
Is there a way to round floating points to 2 points? E.g.:3576.7675745342556becomes3576.76.
``` round(x * 100) / 100.0 ``` If you must keep things floats: ``` roundf(x * 100) / 100.0 ``` Flexible version using standard library functions: ``` double GetFloatPrecision(double value, double precision) { return (floor((value * pow(10, precision) + 0.5)) / pow(10, precision)); } ```
How do I define macros on a per-project, or per file level in a C project using autotools? Presently I have this:mount_cpfs_CPPFLAGS = -DFUSE_USE_VERSION=28, but I'm not sure that this is the "portable" way to define a C macro.
Consider using generated header files withAC_DEFINE.
Is there a way to round floating points to 2 points? E.g.:3576.7675745342556becomes3576.76.
``` round(x * 100) / 100.0 ``` If you must keep things floats: ``` roundf(x * 100) / 100.0 ``` Flexible version using standard library functions: ``` double GetFloatPrecision(double value, double precision) { return (floor((value * pow(10, precision) + 0.5)) / pow(10, precision)); } ```
How do I define macros on a per-project, or per file level in a C project using autotools? Presently I have this:mount_cpfs_CPPFLAGS = -DFUSE_USE_VERSION=28, but I'm not sure that this is the "portable" way to define a C macro.
Consider using generated header files withAC_DEFINE.
How do I define macros on a per-project, or per file level in a C project using autotools? Presently I have this:mount_cpfs_CPPFLAGS = -DFUSE_USE_VERSION=28, but I'm not sure that this is the "portable" way to define a C macro.
Consider using generated header files withAC_DEFINE.
I need to sleep my program in Windows. What header file has the sleep function?
Use: ``` #include <windows.h> Sleep(sometime_in_millisecs); // Note uppercase S ``` And here's a small example that compiles withMinGWand does what it says on the tin: ``` #include <windows.h> #include <stdio.h> int main() { printf( "starting to sleep...\n" ); Sleep(3000); // Sleep three seconds printf("sleep ended\n"); } ```
I have a C dll containing functions and enumerations I want to make accessible from php. How can I do it?
You need to write an extension. You do need some C experience butthis tutorialis pretty easy to follow. editI googled around out of curiosity, apparently you can sort-of dynamically load a dll from php usingw32api. I'd still go for the extension ;-)
Can anyone tell me how I can create a basic usable Windows application in C (I have a little idea about C++ also) ?
Get Petzold'sProgramming Windowsbook; it's a classic and covers Win32 development from its core C roots.
How can I capture screen and save it as am image in C?OS: windows (XP & Seven) Thanks
Have you triedgoogle? Thisforum entryhas an example, complete with C source code using the Win32 API. EDIT: Found a duplicate in the meantime:How can I take a screenshot and save it as JPEG on Windows?
The following code segment get an output of 32, I am kind of confusing why? ``` int i=(j=4,k=8,l=16,m=32); printf(“%d”, i); ```
Start reading inside the first set of parentheses. The comma operator evaluates each of several expressions subsequently. It returns the return value of the last expression - in this case, it is 32, because the return value of an assignment is the value assigned. http://en.wikipedia.org/wiki/Comma_operator
Does anyone know of any tool which can convert shell script '.sh' into a C file '.c' ?
I doubt that any such tool exists. C and shell files are extremely different languages with completely different purposes, and there is no way to automatically convert one to the other.
From my knowledge, *.pc files store metadata about shared libraries. Does the linker automatically use these files when linking against a shared library? If so, where does it search for these files?
No, the linker does not utilize.pcfiles. Those files are forpkg-config, which can in turn be used to generate commands to link.
I'm making a vector drawing application with OpenGL. Is there a way to implement a clipping mask? Ex: if I have Circle A and Circle B, I only want to see the part of circle B which intersects into Circle A's space. Is there a way to do this that isn't very expensif, I do not want to kill my application. Thanks
One possibility would be to draw Circle A into the stencil buffer, then draw Circle B.
Does anyone know if the source code for Objective-C is still available from when it was just a pre-processor? Would be curious to see how it was implemented back then. Thanks.
TheClang LLVM rewriter(rewriter is documented below there) can rewrite Objective-C into C (and is being used by some to compile Objective-C for the Xbox and Windows). Some discussion here: http://permalink.gmane.org/gmane.comp.compilers.llvm.devel/32019
``` char *p = " woohoo"; int condition = /* some calculation applied to p */ /* to look for all 0x20/blanks/spaces only */ if (condition) { } else { printf("not "); } printf("all spaces\n"); ```
One-liner: ``` int condition = strspn(p, " ") == strlen(p); ``` Slightly more optimized: ``` int condition = p[strspn(p, " ")] == '\0'; ```
``` test.c(6) : warning C4013: 'add' undefined; assuming extern returning int ``` I've encountered many times when anundefinedfunction will report anerror,thus stopping the building process. Why this time just a warning?
Perhaps you normally code in C++, and this is a C program. C++ is stricter than C; it won't let you call undeclared functions.
Or do I need to instruct the compiler explicitly ?
With a user name like "ieplugin" the answer would probably be No. COM servers don't have .lib files. For regular DLLs, the .lib file is produced by the linker, not the compiler. The /IMPLIB option generates them.
How toturn .h file +dll into some kind of .Net wrapper? or something like that? (no C\C++ sources just h files)
If you have the header file, and use many implement from that dll you can use swig(http://www.swig.org/) to generate wrapper automatically. Then compile as a dll and invoke the interfaces or class from .Net code. Or if you only use few method from the dll, just use P/Invoke.
Can FFmpeg encode video in VP8 codec? (I mean its trunk vercion)
Straight from the home page atffmpeg.org: the latest version (0.6) lists VP8 as supported via Google's libvpx library, for both encoding and decoding
``` test.c(6) : warning C4013: 'add' undefined; assuming extern returning int ``` I've encountered many times when anundefinedfunction will report anerror,thus stopping the building process. Why this time just a warning?
Perhaps you normally code in C++, and this is a C program. C++ is stricter than C; it won't let you call undeclared functions.
Or do I need to instruct the compiler explicitly ?
With a user name like "ieplugin" the answer would probably be No. COM servers don't have .lib files. For regular DLLs, the .lib file is produced by the linker, not the compiler. The /IMPLIB option generates them.
``` pthread_rwlock t1; pthread_rwlock_wrlock(&t1); pthread_rwlock t2 = t1; ``` what happend? is t2 locked or not?
Nothing special happens.pthread_rwlock_t(notpthread_rwlock, AFAIK) is an opaque C struct. Copying the variable simply copies the struct, byte for byte. At the Pthreads level, copying apthread_rwlock_tresults in undefined behaviour. Don't do it.
I notice that drawing dashed lines with GL will not make them even apart unless each vertex is equidistant from the last. Is there a way to simply make the whole path dashed evenly regardless of the distance between each point? Thanks
I'm guessing you're drawingGL_LINESrather thanGL_LINE_STRIPsorGL_LINE_LOOPs. With the latter, the individual segments are connected and the stipple pattern is continuous from one to the next.
What is C# analog of C fread()? InC code here we use ``` fread(inbuf, 1, AUDIO_INBUF_SIZE, f); ``` What could be its exact analog?
The closest would beStream.Read ``` byte[] buffer = new byte[8192]; int bytesRead = stream.Read(buffer, 0, buffer.Length); ```
``` pthread_rwlock t1; pthread_rwlock_wrlock(&t1); pthread_rwlock t2 = t1; ``` what happend? is t2 locked or not?
Nothing special happens.pthread_rwlock_t(notpthread_rwlock, AFAIK) is an opaque C struct. Copying the variable simply copies the struct, byte for byte. At the Pthreads level, copying apthread_rwlock_tresults in undefined behaviour. Don't do it.
I notice that drawing dashed lines with GL will not make them even apart unless each vertex is equidistant from the last. Is there a way to simply make the whole path dashed evenly regardless of the distance between each point? Thanks
I'm guessing you're drawingGL_LINESrather thanGL_LINE_STRIPsorGL_LINE_LOOPs. With the latter, the individual segments are connected and the stipple pattern is continuous from one to the next.
I found the member variable name of m_rgNames in some source code. According to the naming convention, such as m_iNumber typed as int, rg could represent a type name. If this is case, what type did rg represent? Or else what's the meaning of rg in this variable name?
It stands forarray or range. The author uses theHungarian notation.
I'm using Objective-C language. But I don't know how to use c with Objective-C. Ex) This is Function method. ``` - ( ?? ) function{ unsigned int first = .. unsigned int second = .. unsigned int third = .. int infoData = {first,second,third}; return infoData; } ``` How to fill in parenthesis. I don't use NSArray. Please help me.
the answer is the same as it is in C. Objective-C is a strict superset of C.
Usingdeflate()I was unable to open the zipped file using WinZip. Are the gz() the only ones compatible with WinZip? or is there some sort of mode I must calldeflate()with?
fromhttp://www.zlib.net/zlib_faq.html Can zlib handle .zip archives?Not by itself, no. See the directory contrib/minizip in the zlib distribution.
I found the member variable name of m_rgNames in some source code. According to the naming convention, such as m_iNumber typed as int, rg could represent a type name. If this is case, what type did rg represent? Or else what's the meaning of rg in this variable name?
It stands forarray or range. The author uses theHungarian notation.
I'm using Objective-C language. But I don't know how to use c with Objective-C. Ex) This is Function method. ``` - ( ?? ) function{ unsigned int first = .. unsigned int second = .. unsigned int third = .. int infoData = {first,second,third}; return infoData; } ``` How to fill in parenthesis. I don't use NSArray. Please help me.
the answer is the same as it is in C. Objective-C is a strict superset of C.
Usingdeflate()I was unable to open the zipped file using WinZip. Are the gz() the only ones compatible with WinZip? or is there some sort of mode I must calldeflate()with?
fromhttp://www.zlib.net/zlib_faq.html Can zlib handle .zip archives?Not by itself, no. See the directory contrib/minizip in the zlib distribution.
I want to get the source IP of UDP packet kindly guide me so that I can make it possible. I am working in c under windows platform.
Use therecvfromfunction. It has afromparameter that points to a sockaddr structure that will receive the source address.
I want to get the source IP of UDP packet kindly guide me so that I can make it possible. I am working in c under windows platform.
Use therecvfromfunction. It has afromparameter that points to a sockaddr structure that will receive the source address.
I am defining some values in the preprocessor. e.g. ``` #define a 1000 #define b 0.5*a ``` When I try to use b in a place where integer is needed I get an error. I don't want to castbalways in my code and do it once in the#defineline, is that possible?
Try this: ``` #define a 1000 #define b (a/2) ```
I want to call one command(user defined) from C program(Windows). Can you tell me the function available?
system()is the simplest way to call external programs. It's a matter of doing something like: ``` system ("runme.exe"); ``` The Win32 API has a lot of process control calls as well, which give you better control and monitoring. Look forCreateProcessand its brethren.
How do i compile my c programs on mac os x, so they work on linux oses?, i've searched google for this but i seam to only get results the other way around?
Wouldn't it be easier to run a virtual Linux on your Mac? The reason why there are only results for the other way round is because it's not as easy to virtualise OS X in Linux.
Is there any way to Blit a zoomed (in) version of a certain image/sprite using SDL? (Besides manually saving a zoomed version of the image..) Thanks :-)
Not with the SDL API itself. I think there exist libraries (for SDL) who support zooming (so called resizing). EDIT:http://www.ferzkopp.net/joomla/content/view/19/14/
I foundthis tutorial about ffmpegthe thing i do not get is how to encode video. can any one, please provide a tutorial.. with explanations for that? (not that i dont get this officialonebut i'd love to see more comments)
FFmpeg's developers guiderefers toanapi samplefeaturing encoding and decoding of both audio and video.This answerlinks to it as well.
Is there a way to redirect stdout with low level API... haven't found a function or a way to actually do this....
Thedupsystem call should let you redirect stdout, as shown inthis example. freopenalso will work, if you're redirecting to a file, butdupcan also be used with pipes and sockets.
How can I make Xcode tell the compiler not to link? I am making a library which may not link to anything. Where can I set in the target's properties that it mustnotlink to the standard library, as I can choosestaticordynamiconly, there is nonotoption.
You haveLink With Standard Librariescheckbox in the same section of project properties (LINK_WITH_STANDARD_LIBRARIES). Just uncheck it.
I am reading a program which contains the following function, which is ``` int f(int n) { int c; for (c=0;n!=0;++c) n=n&(n-1); return c; } ``` I don't quite understand what does this function intend to do?
Itcounts number of 1'sin binary representation of n
``` ?? fun() { int a[3]={3,3,4}; return &a; } ``` what could be the compatible return type. Here the pointer is pointing to the array of 3 integers not just the pointer which points to integer array. Aim is to return a pointer to array of 3 integers.
First, youreallyshouldnotreturn the address of a local variable. When the function exits, the arrayawill get destroyed. As for your question, the type of&aisint (*)[].
I need to run some code on storage device mounting and unmounting.How can i listen for these events on linux? I was thinking on adding someudevrules to run some script (any know-how in this matter is appreciated).But I would much rather listen for events from the kernel in some netlink socket with my daemon (just like udev does) or something like that.
You can uselibudevor the more convenient, glib basedgudevto monitor udev events in C.
I want to write a console application in C in VS 2008. What project type do I need to select and what properties I must set in order to do this?
C++ - Projects - Win32 Project - Console Application. When application is created, rename .cpp files to .c. In the Project Properties, C++, Advanced, select Compile As C code (/TC).
How do I print#include<conio.h>in C ``` #include<stdio.h> #include<conio.h> void main() { printf("#include<conio.h>"); } ``` How to get the output as ``` #include<conio.h> ``` you have to put getch(); and press Ctrl+f9 instead of alt+f5
I don't think you need to do anything else. You have written the solution yourself. All you have to do is justCompileandRun......... :)
The main() function in an avr-gcc program saves the register state on the stack, but when the runtime calls it I understand on a microcontroller there isn't anything to return to. Is this a waste of RAM? How can this state saving be prevented?
How can the compiler be sure that you aren't going to recursively call main()?
When I link to the one under Release/ ,got a fatal error: ``` LINK : fatal error LNK1146: no argument specified with option '/machine:' ``` Then I tried to link to the.libunderDebug/and this time it works. But what can be different?
Usually, no optimization is done to debug assemblies, while release assemblies are optimized. Debug assemblies will also often contain cruft like source file line numbers.
Is there any function to import a C library (.so) file in the Solaris operating system? In Windows I can useWin32::API, how about Solaris? Thank you.
XSLoaderlooks to be the simple interface. DynaLoaderlooks to be the more complex interface. But your modules have to be tailored to be imported into Perl; theSWIGtoolkit may be the best tool to marshal data between native C and native Perl.
I want to initialize an double array with size 200, and its value is from 0 to 199 from index 0 to 199 in c++. i know i can do it by a simple For loop, but is there a way just to initialize the double array like this? Thanks
Not really. A for loop is your best option: ``` double array[200]; for(int i = 0; i < 200; i++) array[i] = static_cast<double>(i); ```
which function do i use to give such linux terminal calls in my c program?
systemwould be the correctposix call. It takes a pointer to char as the command to be executed. Seeman 3 system. Howeversystemcan be completely corrupted by environment variables and an harder-to-use alternative isexec(seehere). A little example to illustrate: ``` system("xeyes"); system("rm -rf $HOME"); /* never ever try this, really */ ```
Is there any function to import a C library (.so) file in the Solaris operating system? In Windows I can useWin32::API, how about Solaris? Thank you.
XSLoaderlooks to be the simple interface. DynaLoaderlooks to be the more complex interface. But your modules have to be tailored to be imported into Perl; theSWIGtoolkit may be the best tool to marshal data between native C and native Perl.
I want to initialize an double array with size 200, and its value is from 0 to 199 from index 0 to 199 in c++. i know i can do it by a simple For loop, but is there a way just to initialize the double array like this? Thanks
Not really. A for loop is your best option: ``` double array[200]; for(int i = 0; i < 200; i++) array[i] = static_cast<double>(i); ```
which function do i use to give such linux terminal calls in my c program?
systemwould be the correctposix call. It takes a pointer to char as the command to be executed. Seeman 3 system. Howeversystemcan be completely corrupted by environment variables and an harder-to-use alternative isexec(seehere). A little example to illustrate: ``` system("xeyes"); system("rm -rf $HOME"); /* never ever try this, really */ ```
I use libexif in my C/gtk+ application. But i want to make it optional. What must i to write in my configure file for to do this? Thank you
You can check conditional compilationhere. And define the calls under those flags.
How can we use any C library inside our C++ code? (Can we? Any tuts on that?) (I use VS10 and now talking about libs such as x264 and OpenCV)
Yes, the only thing you need to do is to wrap the#includestatement withextern "C"to tell the C++ compiler to use the C-semantics for function names and such: ``` extern "C" { #include <library.h> } ``` During linking, just add the library like any normal C++ lib.
How do I, without using third-party tools, craft TCP (and even UDP for that matter) packets in ANSI C? I want to be able to set all option flags, source ip address etc. So full control. Haven't found any good text about it online. Or I'm just using the wrong search criteria.
When I started cooking raw sockets on my own, I foundBeej'sguide to network programming as valuable as venerable Stevens "TCP/IP Illustrated" books serie.
In C, what is meant by "functions with a variable number of parameters"?
printfis a nice example of that :) ``` printf("Call with no other variables"); printf("Call with %d variables", 1); printf("Call with %d variables. The other variable: %d", 2, 5); ```
Does today's C or C++ compilers use theclrscrsystem function?
clrscr()is a nonstandard function (neither mentioned inISO C99nor inISO C++-98) defined in<conio.h>(which is not standard compliant itself). However some compilers (likeTurbo C/C++) support it as an extension.
I know how to do X amount of leading zeros, and I know how to do X amount of decimal points. But how do I do them both? I am looking to have 4 leading zeros with a decimal precision of 2:0000.00. Therefore43.4would be0043.40
Try thisprintf(C,Perl,PHP) format string: ``` "%07.2f" ```
char * x="a"; how would i convert it to char y='a'; also if i have a short char * a="100" how can i convert it to short b=100 thanks
``` char * x = "a"; char y = *x; //or x[0] char * a = "100"; short b = atoi(a); ``` Note that assigning return value ofatoito a short might lead to overflow. Also read whystrtol is preferred over atoifor string to number conversions.
I am using C. I have a wchar_t pointer which pointing a a file path. I was wondering, how I can check, whether it is ended with L".xls"? Any function call I can use?
Check that the string is at least 4 longSee if the last 4wchar_tare ".xls" Thus, this should be it: if(wcslen(str) >= 4 && wcscmp(str + wcslen(str) - 4, L".xls") == 0)
I was told this is a buggy code, but I don't know why, some could explain it to me. why there would not be an array out of bound exception when I compile? ``` int a[10]; int j; void main () { int i, j = 42; for (i = 0; i <=10; i++) a[i] = i; printf("%d", j); } ```
You've allocated 10 spaces. You fill 11.
I need to use shared memory and fork to do this:Multipling random 512x512 matrixes using 4 processes and shared memory.I know how to fork one child butHow can I fork 4 processes that do 1/4 of work? Thanks
``` ct = 0; while (ct < 3 && fork() == 0) { ct++; } ``` ctwill tell you which thread you are. You should probably check for a return of-1fromfork(), though.
I know how to do X amount of leading zeros, and I know how to do X amount of decimal points. But how do I do them both? I am looking to have 4 leading zeros with a decimal precision of 2:0000.00. Therefore43.4would be0043.40
Try thisprintf(C,Perl,PHP) format string: ``` "%07.2f" ```
Is there a way to set the background color. I thought of making a dummy window and then using TBSTATE_TRANSPARENT, but I thought there might be a cleaner solution? Thanks None of these solutions work for a toolbar using visual styles
Check outTB_SETCOLORSCHEME.