question stringlengths 25 894 | answer stringlengths 4 863 |
|---|---|
How to hide the mouse pointer on the window screen of GDI, kindly give me some hints.
|
TryShowCursor(false);
Sources:
http://msdn.microsoft.com/en-us/library/ms648396.aspx
http://www.tech-archive.net/Archive/Development/microsoft.public.win32.programmer.gdi/2004-08/0045.html
|
Can anybody suggest how to convert actionscript to c code?
|
There is no automatic way of doing that. The languages offer very different sets of features.
You'll have to do it manually, preferably in a top-down manner. This means that when making the C implementation, write the most abstract functionality first, gradually going into the details.
|
The elements of the array are arranged in non-decreasing order. I need to search the array for a given element in the least possible time.
|
Since the array is sorted you can make use ofBinary Search.
Alinearsearch will takeO(n)time because it does not make use of the sorted property. But abinarysearch will takeO(log n)time.
|
just a quick question regarding C and processes. In my program, I create another child process and use a two-directional pipe to communicate between the child and parent. The child calls execl() to run yet another program.
My question is: I want the parent to wait n amount of seconds and then check if the program tha... |
You can usewaitpid()withWNOHANGas option to poll, or register a signal handler forSIGCHLD.
|
I'm looking to do a parallel programming project in C (probably using pthreads or maybe OpenMP) for a class. It will done by a group of about four students, and should take about 4 weeks. I was thinking it would be interesting to attack some NP-complete problem with a more complex algorithm like a genetic algo with si... |
I remember a 'learning' project at our university about parallelizing alpha-beta pruning algorithms. Alpha-beta pruning itself isn't too complicated and has quite large complexity. If you parallelize it you'll need to install some signaling/data sharing to really benefit from the parallelization. Otherwise some thread... |
I'm trying to write a word to a file using this function:
```
extern void write_int(FILE * out, int num) {
fwrite(&num,sizeof(int),1, out);
if(ferror(out)){
perror(__func__);
exit(EXIT_FAILURE);
}
}
```
But I get a segmentation fault whenever it tries to run the fwrite. I looked at the man page ... |
Try this instead:
```
void write_int(FILE * out, int num) {
if (NULL==out) {
fprintf(stderr, "I bet you saw THAT coming.\n");
exit(EXIT_FAILURE);
}
fwrite(&num,sizeof(int),1, out);
if(ferror(out)){
perror(__func__);
exit(EXIT_FAILURE);
}
}
```
And why was your original functi... |
I'm messing around with GTK and glade for the first time, and I've run across a really annoying issue. When I enter text into a TextView, the TextView automatically resizes larger, pushing other widgets away.
This is a really annoying behavior. I do not want my TextView changing size depending on the amount of text w... |
You should putGtkTextViewintoGtkScrolledWindowwith "hscrollbar-policy" and "vscrollbar-policy" properties set to "automatic".
|
i have a string of the format "ABCDEFG,12:34:56:78:90:11". i want to separate these two values that are separated by commas into two different strings. how do i do that in gcc using c language.
|
One possibility is something like this:
```
char first[20], second[20];
scanf("%19[^,], %19[^\n]", first, second);
```
|
I am writing a small C application that use some threads for processing data. I want to be able to know the number of processors on a certain machine, without usingsystem()& in combination to a small script.
The only way i can think of is to parse/proc/cpuinfo. Any other useful suggestions ?
|
As others have mentioned in comments,thisanswer is useful:
```
numCPU = sysconf( _SC_NPROCESSORS_ONLN );
```
Leaving as a solution for folks that might skip over comments...
|
I'm supporting some c code on Solaris, and I've seen something weird at least I think it is:
```
char new_login[64];
...
strcpy(new_login, (char *)login);
...
free(new_login);
```
My understanding is that since the variable is a local array the memory comes from the stack and does not need to be freed, and moreover ... |
You can only free() something you got from malloc(),calloc() or realloc() function. freeing something on the stack yields undefined behaviour, you're lucky this doesn't cause your program to crash, or worse.
Consider that a serious bug, and delete that line asap.
|
I made a program to connect to a device via Bluetooth and send the data to the web using pure C in gcc. I won't be able to implement any GUI portion in the code right now but I need to deploy it to test users for testing. I want to have the executable with an icon so that a user can click on the executable and the pro... |
This document explains how to add your program to the programs menu:http://standards.freedesktop.org/menu-spec/latest/.
|
i have a small program that uses 32bit object file, and i wish to run it under dos operating system. now, after searching i foundDJGPP.is there a way to use DJGPP to compile my program to 16Bit dos executable format?thanks in advance
|
Take a look atthisrelated Stack Overflow question. It might help.
|
This question already has answers here:Closed13 years ago.
Possible Duplicate:Uses for multiple levels of pointer dereferences?
I have used functions with doubly dereferenced pointers (**var) to return values. However, I was recently asked a question to figure out a use-case where a triple dereferencing (***var) may... |
Three dimensional arrays.
|
I have the simple function below which swap two characters of an array of characters (s). However, I am getting a "Unhandled exception at 0x01151cd7 in Bla.exe: 0xC0000005: Access violation writing location 0x011557a4." error. The two indexes (left and right) are within the limit of the array. What am I doing wrong?
... |
You can't modify a string literal. instead try this:
```
char s[] = "ABC"
swap(s, 0, 1);
printf("%s\n", s);
```
|
Could somebody tell me what is the proper way to convert a NSString* to an ANTLR3 string (used in C) ?
EDIT: this seems to work
```
char buf[255];
if ( YES == [myNSString getCString:buf maxLength:255 encoding:NSStringEncodingConversionAllowLossy] )
{
pANTLR3_UINT8 theExpression = (pANTLR3_UINT8*)buf;
... |
Assuming that you want the complete string without loss, you can use the following code:
```
NSString *myString = ...;
NSUInteger len = [myString lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
char *buf = malloc(len + 1);
if ([myString getCString:buf maxLength:(len + 1) encoding:NSUTF8StringEncoding]) {
// pAN... |
In gcc I can do compile-time warnings like this:
```
#if !defined(_SOME_FEATURE_)
#warning _SOME_FEATURE_ not defined-- be careful!
#endif
```
But in Visual Studio this doesn't work. Is there an alternative syntax for #warning?
|
About the closest equivalent would be#pragma message, or possibly#error(the latter stops compilation, the former just prints out the specified error message).
|
For example when we call say, a recursive function, the successive calls are stored in the stack. However, due to an error if it goes on infinitely the error is 'Segmentation fault' (as seen on GCC).
Shouldn't it have been 'stack-overflow'? What then is the basic difference between the two?
Btw, an explanation would... |
Stack overflow is [a] cause, segmentation fault is the result.
At least on x86 and ARM, the "stack" is a piece of memory reserved for placing local variables and return addresses of function calls. When the stack is exhausted, the memory outside of the reserved area will be accessed. But the app did not ask the ker... |
I have set up the following struct:
```
typedef struct _thread_node_t {
pthread_t thread;
struct thread_node_t *next;
} thread_node_t;
```
... and then I have defined:
```
// create thread to for incoming connection
thread_node_t *thread_node = (thread_node_t*) malloc(sizeof(thread_node_t));
pthread_create(... |
Shouldn'tstruct thread_node_t *next;bestruct _thread_node_t *next;
Also, do away with theexplicitcast.
```
thread_node_t *thread_node = (thread_node_t*) malloc(sizeof(thread_node_t));
```
to
```
thread_node_t *thread_node = malloc(sizeof(thread_node_t));
```
|
I'm doing some networking programming for Windows right now envolving the HTTP protocol.
Is it possible to handle prosies at socket level? And SSL proxies? If not, does Windows provide something at a higher level to handle them? I wouldn't like to use a third party library, but if there's no other way to go I would r... |
You can use for example Windows Internet (WinINet) APIhttp://msdn.microsoft.com/en-us/library/aa383630%28v=VS.85%29.aspxor Windows HTTP Services (WinHTTP)http://msdn.microsoft.com/en-us/library/aa384273%28v=VS.85%29.aspxif are interesting for HTTP protocol only. Advantage of using this API is:
They are Microsoft stan... |
In my code base I find that two modules have structures with the same name. It is giving a name conflict error. Is there a way to resolve it without changing the code?
|
This is a terrible hack, but it would be possible to use a macro to redefine the name of the struct, like so
```
// a.h
struct collide {
int a;
};
// b.h
struct collide {
float b;
};
// test.c
#define collide a_collide
#include "a.h"
#undef collide
#include "b.h"
int main(){
struct a_collide a;
stru... |
suppose there is a string of characters in an array of d[20] . How to convert to a string d so that i can use it in string functions like strcmp..
|
It must be null-terminated. That's the only requirement. I presume you know how to do that.
|
What is a good database with support for C? I want a database that can persist changes when the program is closing and retrieve them when the user starts up the program. I was thinking maybe like SQLite or Berkeley DB. Some documentation would be great too. I just need a database with a library for C. It will be used ... |
For embedded data, try SQLite.
Although if it's just program settings for a single instance of the program, an XML file might be your best bet. There are lots of freely-available XML parsers for C.
|
I have some C code that parses a file and generates another file of processed data. I now need to post these files to a website on a web server. I guess there is a way to do a HTTP POST but I have never done this in c (using GCC on Ubuntu). Does anyone know how to do this? I need a starting point as I have no clue of ... |
libcurlis probably a good place to start.
|
I have a string asconst char *str = "Hello, this is an example of my string";
How could I get everything after the first comma. So for this instance:this is an example of my string
Thanks
|
You can do something similar to what you've posted:
```
char *a, *b;
int i = 0;
while (a[i] && a[i] != ',')
i++;
if (a[i] == ',') {
printf("%s", a + i + 1);
} else {
printf("Comma separator not found");
}
```
Alternatively, you can take a look atstrtokandstrstr.
Withstrstryou can do:
```
char *a = "hello... |
```
#include<stdio.h>
#include<ctype.h>
int main()
{
char a,b;
FILE *fp;
fp=fopen("lext.txt","w");
fprintf(fp,"PLUS");
return 0;
}
```
the error i get is this
```
/tmp/ccQyyhxo.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
```
|
You are compiling a.cppfile withgcc. Rename the file to end with.cso it compiles as C code or compile it with the C++ driverg++. That will link in thestdc++library providing these functions.
|
I'm developing C extensions from python and I obtain some segfaults (inevitable during the development...).
I'm searching for a way to display at which line of code the segfault happens (an idea is like tracing every single line of code), how can I do that?
|
If you are on linux, run python under gdb
```
gdb python
(gdb) run /path/to/script.py
## wait for segfault ##
(gdb) backtrace
## stack trace of the c code
```
|
I am looking for a SOAP Library for C. I know there is gSOAP. What other options do I have?
|
Take a look at thisblogentry. I know it's C++, but I have had good results with Apache's AXIS. If you can use a C++ compiler, you can wrap around a C library to your generated classes.
|
```
char
char* c[30];
c = (char*) malloc(30*sizeof(char) );
```
How does this give an incompatible declaration in built in function warning and and incompatible types in assignment error in the line where i have declared malloc . According to the syntax of malloc , i shouldnt have any error
|
You have declaredcas an array. You can't change the value of an array, and an array is not a pointer.
chas the type(char*)[30](i.e. an array of 30 char pointers) , notchar*as your cast suggests.
If you're trying to create a dynamically allocated char "array" for 30 chars, use
```
char *c = malloc(30);
```
If you r... |
I have a very simple test program, running on Solaris 5.8:
```
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char *paths;
paths = getenv("PATH");
printf("Paths: %s\n", paths);
free(paths); // this causes a bus error
return 0;
}
```
If I don't callfree()at the end, it displays the mess... |
Because you're not supposed tofreethe value returned fromgetenv()(it's a static variable).
|
I have global static variables in a C library, which generate exceptions in a multithread run. I need to make them safe in some way (i.e., each thread should relate to a different instance of these variables). Any recommended methods?
|
There is no standard way that works across all C implementations, but implementation-specific solutions exist. For example, with Microsoft's compiler (seethe docs),
```
__declspec( thread ) int tls_i = 1;
```
makestls_ilive in thread-local storage (each thread has its own separate instance of this variable). Withg... |
i have anchararrayb[20]which i want to write into a file . After every iteration the value ofb[20]changes , so i would like to write the string in each line of the file in each iteration . So how can i change a new line in a file and also put in a array of character?
|
Something like:
```
FILE *fp = fopen("file.txt","w");
// check for error
char b[20];
while(some_condition) {
// populate the char array b and terminate it with NULL char.
// write to file...and write a newline.
fprintf(fp,"%s\n",b);
}
```
|
I have checked the assembler options ofGNU assembler asand I didn't find an option to specify the output object file format. If I am using the following command
```
as -o foobar.o foobar.s
```
What object file format will I get?
The as manual says that "The GNU as can be configured to produce several alternative ob... |
On linux the output from gas is ELF already, it is unlikely you have a version which is building the old a.out format, or that you are using a cross compiler to say build to MachO or PE.
|
How can I convert a mixed case string to a lowercase string in C?
|
It's in the standard library, and that's the most straight forward way I can see to implement such a function. So yes, just loop through the string and convert each character to lowercase.
Something trivial like this:
```
#include <ctype.h>
for(int i = 0; str[i]; i++){
str[i] = tolower(str[i]);
}
```
or if you p... |
How can we implement the modulo operator as a function in C without using the operator?
|
Do an integer division followed by a multiplication, and subtract.
```
#include <stdio.h>
int main()
{
int c=8, m=3, result=c-(c/m*m);
printf("%d\n", result);
}
```
|
I want to run the following command from a C program to read the system's CPU and memory use:
```
ps aux|awk 'NR > 0 { cpu +=$3; ram+=$4 }; END {print cpu,ram}'
```
I am trying to pass it to theexeclcommand and after that read its output:
```
execl("/bin/ps", "/bin/ps", "aux|awk", "'NR > 0 { cpu +=$3; ram+=$4 }; EN... |
You can't do this here this way.
The problem is that you want to execute several commands. execl is for executing a single command. The statement you have is using shell syntax (notably the | )
You will have better luck combining it all up in a single string and using the system(3) call.
|
If I define these variables:
```
double x0, xn, h;
int n;
```
and I have this mathematical expression:
```
h = (xn - x0)/n;
```
Is it necessary that I cast n into double prior doing the division for maximum accuracy like in
```
h = (xn - x0)/ (double) n;
```
I wrote a program to check the above but both expressi... |
Your understanding is correct, and the book you read is either mistaken or being over-cautious (like people who claim that you should always test0 == xinstead ofx == 0). The expression without the cast should always give precisely the same result as the expression with the cast.
|
I need user to define all the environment variables needed for my program in a text file as shown below.
MyDLLPath = C:\MyDLLPathMyOption = Option1PATH = %MyDLLPath%;%PATH%;
In my program I read each line and call putenv with the string. Problem is that the environment substitutions (%MyDLLPath%) are not being expan... |
You could useExpandEnvironmentStrings.
|
Is there a way I can find out all changes to memory by a particular piece of code( a function or a line of code ) without knowing in advance where I expect the changes(I want to watch the whole program memory space)? watch in gdb requires me to know what I expect is changing...
|
If you can run the software you wish to probe on Linux or Mac OS, I'd suggest looking intoValgrind, specifically Valgrind's Memcheck tool.
In a nutshell, Valgrind runs your program on a "synthetic CPU". It doesn't directly execute the program's code on the real hardware. As a result, it's able to instrument everythin... |
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened,visit the he... |
UseGTK+. It's written in C and exposes a well-designed C API. Theirtutorialis quite excellent.
GTK+ is the toolkit for GNOME, so your applications will fit right in with many Linux desktops.
|
I'm trying to detect the compiler used to compile my source code. I can easily find predefined macros to check for MSVC or GCC (seehttps://github.com/cpredef/predeffor example), but I cannot find any macro to check for clang.
Does someone know if clang defines a macro like__CLANG__in order to know what is currently c... |
To get a list of all the predefined macros that the compiler uses, use this:
```
clang -dM -E -x c /dev/null
```
You can do the same for gcc.
|
I have a struct like this
```
typedef struct bookStruct
{
char title[80];
char author[80];
} BookType;
```
And I have two strings like this
```
char *title = "A Book on C";
char *author = "A. Kelly";
```
Now I can't create aBookTypelike this
```
BookType book = {title, author};
```
Can anyone tell me what ... |
There are two possible solutions to your problem. The first of which is using the string literals in the place of construction:
```
BookType book = { "A book on C", "A. Kelly" };
```
In this case the compiler will copy the literals to the appropriate variables. If you cannot use the literals in the initialization, t... |
I'm trying to use CMake to build a program relying on blas, I'm detecting blas using :
```
include (${CMAKE_ROOT}/Modules/FindBLAS.cmake)
```
The problem is, FindBLAS require a fortran compiler and complain with
```
-- Looking for BLAS... - NOT found (Fortran not enabled)
```
As blas is already installed on my mac... |
TheCMake Documentationis your friend, what you need isenable_language.
|
I was wondering was the best way to invert the color pixels in the frame buffer is. I know it's possible to do withglReadPixels()andglDrawPixels()but the performance hit of those calls is pretty big.
Basically, what I'm trying to do is have an inverted color cross-hair which is always visible no matter what's behind ... |
Give something likethisa try:
```
glEnable(GL_COLOR_LOGIC_OP);
glLogicOp(GL_XOR);
// render geometry
glDisable(GL_COLOR_LOGIC_OP);
```
|
Is there a limit on the stack size of a process in Linux? Is it simply dependent on the RAM of the machine?
I want to know this in order to limit the depth of recursive calls to a function.
|
The stack is normally limited by a resource limit. You can see what the default settings are on your installation usingulimit -a:
```
stack size (kbytes, -s) 8192
```
(this shows that mine is 8MB, which is huge).
If you remove or increase that limit, you still won't be able to use all the RAM in the m... |
I am writing a C program. It takes its arguments from commandLine. I want to change the commandLine arguments in the code. As they are defined as "const char *", I can not change them using "strcpy", "memcpy", ... Also, you know, I can not just change their type from "const char *" to "char *".
Is there any way to cha... |
According to C99 §5.1.2.2.1/1, the signature formainis
```
int main(int argc, char *argv[]) { /* ... */ }
```
So youareallowed to remove theconst. Just don't cause a buffer overrun bystrcpying in longer strings than the original arguments, or attempting to install more arguments than originally passed.
Everyone els... |
I'm writing a program that calculates the Jacobi algorithm. It's written in Objective-C since it runs on a Mac, but the majority is written in standard C. I'm using a two-dimensional C array and anNSArraycontaining 5NSTextFieldlabels.
The following code yields anEXC_BAD_ACCESSerror:
```
for ( int i = 0; i < 5; i++ )... |
Most likely, you are referencing an object that has been released. Is your NSArray or objectAtIndex: nil at that point? Can you show the lines where you instantiate these objects?
|
I want to know how to announce int to make sure it's 4 bytes or short in 2 bytes no matter on what platform. Does C99 have rules about this?
|
C99 doesn't say much about this, but you can check whethersizeof(int) == 4, or you can use fixed size types like uint32_t (32 bits unsigned integer). They are defined instdint.h
|
In a book I am reading there is a piece of code :
```
string x;
size_t h=0;
for(const char* s=x.c_str();*s;++s)
h=(h*17)^*s;
```
Regarding this code, I have two questions:
how can*sbe a condition? what does it mean?what does"h=(h*17)^*s"mean?
Thanks for help!
|
how can *s be a condition? what does it mean?
It means "while the value pointed to bysis not zero." C strings are null-terminated, so the last character in the string returned byc_str()will be the null character (\0, represented by all bits zero).
what does "h=(h*17)^*s" mean?
It multiplieshby17thenxors it with th... |
Is there a way to know whether a variable is defined, by looking at the executable.
Lets say I declare
```
int i;
```
in the main function. By compiling and linking I get an executable my_program.exe.
Now, by looking inside my_program.exe, can I say if it has aninteger variablei?
|
Not unless you compile with debugging enabled.
|
Anyone can explainin detailswhat the following macro does?
```
#define write_XDATA(address,value) (((char *)0x010000) [address]=value)
```
thx!
|
You use it:
```
write_XDATA( Address, Value );
```
and it is expanded:
```
((char*)0x010000)[Address]=Value;
```
which is equivalent to the following:
```
char* baseAddress = (char*)0x010000;
*(baseAddress + Address) = Value;
```
so basically it writes a byte stored inValueat the address0x010000 + Address.
|
I am having oneGtkVboxand I am adding it toGtkViewPort. View port is created from Glade file.
Now the problem is that my vbox keeps updating on every second (I keep adding widgets to vbox on every second) this vbox but my screen did not get updated as add widgets to my vbox.
I can't create new vbox every time as I n... |
Make sure you also callgtk_widget_show()on any widgets you add, or evengtk_widget_show_all()if what you add can have sub-widgets.
|
Any reasons why this can not be standard behavior offree()?
multiple pointers pointing to the same object:
```
#include <stdlib.h>
#include <stdio.h>
void safefree(void*& p)
{
free(p); p = NULL;
}
int main()
{
int *p = (int *)malloc(sizeof(int));
*p = 1234;
int*& p2 = p;
printf("p=%p p2=%p\n", ... |
If it did, you would have to pass a pointer to a pointer to the function:
```
int * p = malloc( sizeof( int ));
free( & p );
```
which I'm sure many people would get wrong.
|
I've a problem , as the following code discribe itself.
```
1 #include<stdlib.h>
2 #include<stdio.h>
3 void log()
4 {
5 printf("Log [Line:%d]\n",__LINE__);
6 }
7 int main()
8 {
9 log();
10 log();
11 }
```
The expected result isLog [Line:9]Log [Line:10]But, the fact isLog [Line:5]Log [Li... |
You need to write a macro:
```
#define LOG printf("Log [Line:%d]\n",__LINE__)
```
then use it:
```
int main() {
LOG;
LOG;
}
```
This works because the macro is expanded at its point of use, giving the__LINE__macro the correct value.
|
As the title says, thejava.io.tmpdirproperty in Java is really nice, and I can't find an equivalent for C. I'm writing for Windows and in Visual Studio. I don't want to just use something likeC:\Tempbecause in later versions of windows the appropriate directory could be something likeC:\Users\[UserName]\AppData\Local\... |
If you're using the Win32 API, you can useGetTempPath().
|
I did the following steps to use the CDialog in win 32 application:
Changed the use of MFC to "use mfc shared DLL".Added a dialog resource and added a class for the dialog.Included the dialog class in my main.Tried to call do modal.
when i try to call do modal...i am getting an debug assertion failed.. can anybody h... |
"Shared DLL" does matter only when you distribute your application. With that optionthe executable does not contain MFC core libs so you'll have to provide them with the exe.
Now, if the wizard generated the dialog class, this is the standard way to call it:
```
#include "MyDlg.h"
...
void DisplayMyDialog() {
CMy... |
I'm a bit fuzzy on the basic ways in which programmers code differently in C and C++. One thing in particular is the usage of strings in C++ over char arrays, or vice versa. So, should I use strings or char arrays, in general, and why?
|
In C++ you should in almost all cases usestd::stringinstead of a raw char array.
std::stringmanages the underlying memory for you, which is by itself a good enough reason to prefer it.
It also provides amucheasier to use and more readable interface for common string operations, e.g. equality testing, concatenation, ... |
I have an open socket to a remote terminal. Using the answer to "Force telnet client into character mode" I was able to put that terminal into character mode.
My question is, how do I hide the cursor in the remote terminal using this method?
|
To expand upon mjh2007's answer, the following c/c++ code will implement sending the escape codes to the terminal, and is slightly more readable than raw hex numbers.
```
void showCursor(bool show) const {
#define CSI "\e["
if (show) {
fputs(CSI "?25h", stdout);
}
else {
fputs(CSI "?25l", stdout);
}
#... |
K&R C Programming Language: pg. 105Extendentabanddetabto accept the shorthandentab -m +nto mean tab stops everyncolumns, starting at columnm.
entabreplaces a number of spaces with a tab character anddetabdoes the opposite. The question I have concerns the tab stops andentab. I figure that fordetabit's pretty easy to ... |
"tab stops every n columns, starting at column m" tells you how large each tab stop is, at least by my reading: it's justn. Only the first tab stop is different; that one ism.
|
I am trying to compile a program I took off a cd from a book that uses directx to render 3d objects. when i press compile I get the following error
```
C1083: Cannot open include file: 'dxerr9.h': No such file or directory
```
I am using VC++ 2008 Express Edition and i am running off of Vista. I went to the followin... |
It seems your program was written using older version of DirectX SDK. The 'dxerr9.h' is present at least in "Microsoft DirectX 9.0 SDK (December 2004)", but is absent at least in "Microsoft DirectX SDK (August 2009)".
|
I have a static library project in Eclipse that was compiled into a .a file. So now how would I use the functions and constants in that library? Would I just put in into my includes:
```
#include "mylib.a"
```
|
The static library would be included in the linking process, not in the source code. The library should have an associated .h header file containing the function definitions and constants that you would #include in your source code. Something like
```
#include "mylib.h"
```
Then you would compile the source and link... |
I am profiling a C program using Mac's Shark which shows that some of CPU time goes to "blkclr" in "mach_kernel". What does this kernel function do? I speculate it is related to memory allocation, but I am not sure. I have googled for some time, but could not find the answer, either. Does someone know this? Thanks in ... |
Zeroes out a block of memory
http://www.cs.cmu.edu/afs/cs.cmu.edu/project/mach/public/src/mkernel/src/kernel/mips/mips_mem_ops.c
|
Usually it will ignore C files that are not documented, but I'd like to test the Callgraph feature for example, do you know a way around this without changing the C files?
|
Set the variableEXTRACT_ALL = YESin your Doxyfile.
|
I have to write a macro that get as parameter some variable, and for each two sequential bits with "1" value replace it with 0 bit.
For example: 10110100 will become 10000100.And, 11110000->0000000011100000->100000000
I'm having a troubles writing that macro. I've tried to write a macro that get wach bit and replace... |
```
#define foo(x,i) (((x) & (3<<i)) == (3<<i)) ? ((x) - (3 << i)) : (x)
#define clear_11(x) foo(foo(foo(foo(foo(foo(foo(foo(foo(x,8),7),6),5),4),3),2),1),0)
```
This will do the job. However the expansion is quite big and compilation may take a while. So do not try this at work ;)
|
So I have some cool Image Processing algorithm. I have written it in OCaml. It performs well. I now I can compile it as C code with such commandocamlc -output-obj -o foo.c foo.ml(I have a situation where I am not alowed to use OCaml compiler to bild my programm for my arcetecture, I can use only specialy modified gcc... |
Yes. But all generalisations about such matters are just that, generalisations, and you (and others here) will be able to find counter-examples.
Of course this answer is, itself, a generalisation.
|
'??' gets converted into '^' if I compile mn VC++ program and run it
e.g.
```
sprintf( ch, "??")
```
prints out
```
^
```
But if I run the same code in Turbo C/C++, there is no such problem. Why is it happening on VC++ on Windows?
|
??alone is not atrigraph, although??'corresponds to^.
Perhaps you typed it here different from what you have in code and you can't see the trailing single quote in your string because it's too close to the closing quote.
So in code you probably have:
```
sprintf( ch, "??'");
```
|
This is a very very basic question and I know one way is to do the following:
```
char buffer[33];
itoa(aq_width, buffer,10);
```
where aq_width is the int, but then I can't guarantee what size of buffer I would need in order to do this... I can always allocate a very large buffer size, but that wouldn't be very nic... |
```
std::stringstream ss;
ss << 3;
std::string s = ss.str();
assert(!strcmp("3", s.c_str()));
```
|
Closed. This question isopinion-based. It is not currently accepting answers.Want to improve this question?Update the question so it can be answered with facts and citations byediting this post.Closed7 years ago.Improve this question
I thought one of the best ways to familiarise myself with C/C++, is to make a helpfu... |
If it is for the sake of an exercise, writing a library to deal with fractions is a good one.
http://en.wikipedia.org/wiki/Fraction_(mathematics)
Implement the basic operations and a way to print them.
|
Sorry to put a post up about something so simple, but I don't see what I'm doing wrong here.
```
char data[1024];
DWORD numRead;
ReadFile(handle, data, 1024, &numRead, NULL);
if (numRead > 0)
printf(data, "%.5s");
```
My intention with the above is to read data from a file, and then only print out 5 characters... |
You have your parameters in the wrong order. The should be written:
```
printf("%.5s", data);
printf("%.*s", numRead, data);
```
The first parameter toprintfis the format specifier followed by all the arguments (which depend on your specifier).
|
I have a double thats got a value of something like 0.50000 but I just want 0.5 - Is there any way to get rid of those trailing 0's? :)
|
In C,
```
printf("%g", 0.5000);
```
Note: (from GNU libc manual)
The%gand%Gconversions print the argument in the style of%eor%E(respectively)if the exponent would be less than -4 or greater than or equal to the precision; otherwise
they use the ‘%f’ style. A precision of 0, is taken as 1. Trailing zeros are remov... |
I need help working with very big numbers. According to Windows calc, the exponent
```
174^55 = 1.6990597648061509725749329578093e+123
```
How would I store this using C (c99 standard)?
```
int main(){
long long int x = 174^55; //result is 153
printf("%lld\n", x);
}
```
|
Normal types in C can usually only store up to 64 bits, so you'll have to store big numbers in an array, for example, and write mathematical operations yourself. But you shouldn't reinvent the wheel here - you could try theGNU Multiple Precision Arithmetic Libraryfor this purpose.
And as the comments already pointed ... |
I'm trying out Visual studio 2010 by compiling a C program. After it displays the solution in the "DOS" command window, the window is immediately closed. In Visual studio 2008, one gets the message press any key to continue and pressing a key closes the command prompt window. How do I set this behavior in 2010?
|
After a bit of googling, I foundthissolution that does not involve modifying your code. It contains a workaround that involves modifying your .vcxproj file.
To do this from within Microsoft Visual C++ 2010 Express (I'm assuming it is similar for Visual Studio 2010), open your project and navigate to the following men... |
Closed.This question is seeking recommendations for books, tools, software libraries, and more. It does not meetStack Overflow guidelines. It is not currently accepting answers.We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answer... |
Shedskin translates Python code to C++.
|
```
int main ( )
{
char C[] = "Hello World";
write(0,C,sizeof(C));
return 0;
}
```
In the above program, I am writing to File descriptor ZERO which I suppose by default is STDIN.. Then why I am I getting output at STDOUT?
```
shadyabhi@shadyabhi-desktop:~$ ./a.out
Hello Worldshadyabhi@shadyabhi-desktop:~... |
Standard input is for reading, not writing. What happens when you write to standard input (or read from standard output) is unspecified. Here, both standard input and standard output point to the pseudo-terminal into which the application runs, and the terminal emulator did not take care to make the '0' descriptor "re... |
Is it possible to use C/C++ code in Android?
And how easy is it?
|
Its possible. Use the Native Development Kit (NDK). Seeherefor more discussion and links.
How easy is it? I don't know, I've never tried!
|
I know how to swap two variables in C++, ie you usestd::swap(a,b).
Does the C standard library have a similar function to C++'sstd::swap(), or do I have to define it myself?
|
You need to define it yourself.
C doesn't have templates.If such function does exist it would look likevoid swap(void* a, void* b, size_t length), but unlikestd::swap, it's not type-safe.And there's no hint such function could be inlined, which is important if swapping is frequent (in C99 there'sinlinekeyword).We cou... |
I'm newly using CODE::BLOCKS+mingw compiler
If I don't type return 0 at the end of program,I can see that main() is returning some integer,I learnt that main() returning 0 infers program executes successfully.I don't find any flaw in my code, why is it returning some integer?
secondly
any function returns its value t... |
The C++ Standard says that if you don't explicitly return a value, the compiler must generate code as if you had typed:
```
return 0;
```
Exactly what the return value means and how it is returned is implementation specific. For most OSs, the return value becomes the exit code of the process.
|
I am calling a third party API which creates a socket, does a connect and then calls select API by passing the socket to block forever.
I don't have access to the socket. Is there some way in which I can make the select call come out from my application without having access to the socket?
My platform is Windows.
|
You can't normally do this unless you can access either the socket or the select set used.
If you can get access to the socket, close it viaclosesocket().
If you can get access to the read set, stuff a dummy socket there, then see previous point.
If none of these work you can either:
Ensure this happens in a separa... |
C/Obj-C Developers- I am looking for a way to listen for a specific word or small set of words to be spoken and fire an event. Needs to be able to run on the iPhone/iPad ... Looking for ideas?
|
There seem to be a few commercial options, but from what I can find no (Easy) free method. Searching around seems to indicate that Julius (http://julius.sourceforge.jp/en_index.php) could work for iPhone, but there aren't any instructions I can find.
Commercial:
* Creaceed
|
I am aware that it is not possible to echo the * while you type in standard ANSI C. But is there a way to display nothing while someone is typing their password in the console. What I mean is like the sudo prompts in a Unix/Linux terminal. Like if you type in the command:sudo cp /etc/somefile ~/somedir. You are usuall... |
The function that you are looking for is:getpass(). You will note, though, that it is marked as "LEGACY". Although it isn't going to go anywhere, the function doesn't allow the size of the input buffer to be specified, which makes it not a very good interface. As Jefromi has noted, the glibc manual providesportable e... |
This question already has answers here:What is this strange function definition syntax in C? [duplicate](6 answers)Closed8 years ago.
When reading some FreeBSD source code (See:radix.hlines 158-173), I found variable declarations that followed the "function heading" in the definition.
Is this valid in ISO C (C99)? w... |
That looks like K&R (pre-ANSI) style. I don't think it's valid C99, but are they using C99? Joel
|
Whenever any question is asked, and a reference text is needed, I never seeMSDN C++ Language Referencebeing referred.
I was browsing through it and I personally feel that it is extremely well written.
Is there some specific reason it is not used as often as a standard?
Is it because it contains some VC++ specific f... |
I believe it's because those of us referencing a reference reference the actual standard itself.
|
Does anyone know any more details about google's web-crawler (aka GoogleBot)? I was curious about what it was written in (I've made a few crawlers myself and am about to make another) and if it parses images and such. I'm assuming it does somewhere along the line, b/c the images in images.google.com are all resized.... |
you can find a bit about how googlebot works here:
http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=158587
for example the "fetch as googlebot" tool lets you see a page as Googlebot sees it.
|
Given a list of URLs, such as a/b/e/f, b/c/d/k/g, s/e/c/d, how to match an input URL to the one in the list, for example, an input c/d should be matched to s/e/c/d, not b/c/d/k/g
|
Why not b/c/d/k/g? Are the "Url"s simply strings? If so simply search it using strstr or one of its derivative (wcsstr, _mbsstr, _mbsstr_l).
|
I have to link dynamically with OpenSSL libeay32.dll.
I'm writing native c++ console application using Visual C++ Express 2008.
I'm including a header evp.h from OpenSSL distribution. Building and...:
```
error LNK2001: unresolved external symbol _EVP_aes_256_cbc
error LNK2001: unresolved external symbol _EVP_Decryp... |
There is probably a .lib file you also need to add to your compiler's linker input. Check the documentation for the library you're using.
|
I'm using a library which has both a C interface and a C++ interface in my C++ program. The C++ one is a bit immature and I must stick with the C one. I was wondering, in more general terms, is there anything specific to keep in mind when mixing C-style binary object files with a C++ project?
|
For C functions to be called from C++, they have to be declared asextern "C". Usually something like this is used in headers:
```
#if defined(__cplusplus)
extern "C" {
#endif
void f();
void g();
#if defined(__cplusplus)
}
#endif
```
|
Where can I find the implementation of time.h in the C Standard Library, i.etime.c?
I tried with Google Code Searchtime.cIs the implementation in the Linux kernel?
|
time.his a header from the C standard library.
You will find implementations of the various functions this header provides in the c library implementation of your system.
For instance, the implementation for thedifftimefunction in thelibcused forNetBSDcan be found insrc/lib/libc/time/difftime.c.
|
if for example i have :
```
#define PRINT(x) fprintf(stderr, x);
```
and in code i append it :
```
PRINT(("print this"))
```
output is :
[print this]
if i append it :
```
PRINT(("print %s", "this"))
```
output is :
[this]
could someone explain me why it receives just the "this" argument and not the whole str... |
```
PRINT(("print %s", "this"))
```
becomes:
```
fprintf(stderr, ("print %s", "this"));
```
which is equivalent to:
```
fprintf(stderr, "this");
```
However,variadic macros(from C99) work:
```
#define PRINT(...) fprintf(stderr, __VA_ARGS__)
int main() {
PRINT("print %s", "this");
return 0;
}
```
|
I am calling a third party API which creates a socket, does a connect and then calls select API by passing the socket to block forever.
I don't have access to the socket. Is there some way in which I can make the select call come out from my application without having access to the socket?
My platform is Windows.
|
You can't normally do this unless you can access either the socket or the select set used.
If you can get access to the socket, close it viaclosesocket().
If you can get access to the read set, stuff a dummy socket there, then see previous point.
If none of these work you can either:
Ensure this happens in a separa... |
C/Obj-C Developers- I am looking for a way to listen for a specific word or small set of words to be spoken and fire an event. Needs to be able to run on the iPhone/iPad ... Looking for ideas?
|
There seem to be a few commercial options, but from what I can find no (Easy) free method. Searching around seems to indicate that Julius (http://julius.sourceforge.jp/en_index.php) could work for iPhone, but there aren't any instructions I can find.
Commercial:
* Creaceed
|
I am aware that it is not possible to echo the * while you type in standard ANSI C. But is there a way to display nothing while someone is typing their password in the console. What I mean is like the sudo prompts in a Unix/Linux terminal. Like if you type in the command:sudo cp /etc/somefile ~/somedir. You are usuall... |
The function that you are looking for is:getpass(). You will note, though, that it is marked as "LEGACY". Although it isn't going to go anywhere, the function doesn't allow the size of the input buffer to be specified, which makes it not a very good interface. As Jefromi has noted, the glibc manual providesportable e... |
This question already has answers here:What is this strange function definition syntax in C? [duplicate](6 answers)Closed8 years ago.
When reading some FreeBSD source code (See:radix.hlines 158-173), I found variable declarations that followed the "function heading" in the definition.
Is this valid in ISO C (C99)? w... |
That looks like K&R (pre-ANSI) style. I don't think it's valid C99, but are they using C99? Joel
|
Whenever any question is asked, and a reference text is needed, I never seeMSDN C++ Language Referencebeing referred.
I was browsing through it and I personally feel that it is extremely well written.
Is there some specific reason it is not used as often as a standard?
Is it because it contains some VC++ specific f... |
I believe it's because those of us referencing a reference reference the actual standard itself.
|
Does anyone know any more details about google's web-crawler (aka GoogleBot)? I was curious about what it was written in (I've made a few crawlers myself and am about to make another) and if it parses images and such. I'm assuming it does somewhere along the line, b/c the images in images.google.com are all resized.... |
you can find a bit about how googlebot works here:
http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=158587
for example the "fetch as googlebot" tool lets you see a page as Googlebot sees it.
|
Given a list of URLs, such as a/b/e/f, b/c/d/k/g, s/e/c/d, how to match an input URL to the one in the list, for example, an input c/d should be matched to s/e/c/d, not b/c/d/k/g
|
Why not b/c/d/k/g? Are the "Url"s simply strings? If so simply search it using strstr or one of its derivative (wcsstr, _mbsstr, _mbsstr_l).
|
I have to link dynamically with OpenSSL libeay32.dll.
I'm writing native c++ console application using Visual C++ Express 2008.
I'm including a header evp.h from OpenSSL distribution. Building and...:
```
error LNK2001: unresolved external symbol _EVP_aes_256_cbc
error LNK2001: unresolved external symbol _EVP_Decryp... |
There is probably a .lib file you also need to add to your compiler's linker input. Check the documentation for the library you're using.
|
I'm using a library which has both a C interface and a C++ interface in my C++ program. The C++ one is a bit immature and I must stick with the C one. I was wondering, in more general terms, is there anything specific to keep in mind when mixing C-style binary object files with a C++ project?
|
For C functions to be called from C++, they have to be declared asextern "C". Usually something like this is used in headers:
```
#if defined(__cplusplus)
extern "C" {
#endif
void f();
void g();
#if defined(__cplusplus)
}
#endif
```
|
Where can I find the implementation of time.h in the C Standard Library, i.etime.c?
I tried with Google Code Searchtime.cIs the implementation in the Linux kernel?
|
time.his a header from the C standard library.
You will find implementations of the various functions this header provides in the c library implementation of your system.
For instance, the implementation for thedifftimefunction in thelibcused forNetBSDcan be found insrc/lib/libc/time/difftime.c.
|
if for example i have :
```
#define PRINT(x) fprintf(stderr, x);
```
and in code i append it :
```
PRINT(("print this"))
```
output is :
[print this]
if i append it :
```
PRINT(("print %s", "this"))
```
output is :
[this]
could someone explain me why it receives just the "this" argument and not the whole str... |
```
PRINT(("print %s", "this"))
```
becomes:
```
fprintf(stderr, ("print %s", "this"));
```
which is equivalent to:
```
fprintf(stderr, "this");
```
However,variadic macros(from C99) work:
```
#define PRINT(...) fprintf(stderr, __VA_ARGS__)
int main() {
PRINT("print %s", "this");
return 0;
}
```
|
Does anyone know any more details about google's web-crawler (aka GoogleBot)? I was curious about what it was written in (I've made a few crawlers myself and am about to make another) and if it parses images and such. I'm assuming it does somewhere along the line, b/c the images in images.google.com are all resized.... |
you can find a bit about how googlebot works here:
http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=158587
for example the "fetch as googlebot" tool lets you see a page as Googlebot sees it.
|
Given a list of URLs, such as a/b/e/f, b/c/d/k/g, s/e/c/d, how to match an input URL to the one in the list, for example, an input c/d should be matched to s/e/c/d, not b/c/d/k/g
|
Why not b/c/d/k/g? Are the "Url"s simply strings? If so simply search it using strstr or one of its derivative (wcsstr, _mbsstr, _mbsstr_l).
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.