question
stringlengths 24
425
| answer
stringlengths 5
405
|
---|---|
```
#include<stdio.h>
int main()
{
int a=5,*b,*c;
b=&a;
c=b;
*b++=*c++;
printf(" %d %d %d\n",&a,b,c);
}
```
Here if adress of a is x, then value of b and c is both becoming x+4. But shouldn't two ++ operator increase atleast one value by 8
| No. Don't confuse the value of a pointer with the value that it pointsto.
The expression*b++means: retrieve the value that b pointsto, and then increment the value of b.
|
For C/C++ applications in Windows(non GUI), what should be the proper list of error codes for different failures? I have seen various lists such as from IBM and others, but I was wondering if there was some consensus on typical error codes given to the user when the program exits.
| There are three portable values for the argument toexit:0,EXIT_FAILURE, andEXIT_SUCCESS.0is equivalent toEXIT_SUCCESS.
|
I have 3 console programs (.exe), and I want to run them from one console application without showing the windows of the 3 console programs.
All programs are written in VC++.
Any suggestions about how I can do this?
| You can use ShellExecute command to run the other application
|
If I have something like this
```
if(pointer!=NULL&&(*pointer)==x) { ... }
```
Will it segfault if pointer is NULL? If it is compiler specific, I'd like to know how it is in GCC.
| No, because ofshort circuit evaluation.
If the LHS isfalse, then the RHS won't be evaluated. Therefore, if it's aNULLpointer, it will never hit the RHS and attempt to dereference it.
|
If I have something like this
```
if(pointer!=NULL&&(*pointer)==x) { ... }
```
Will it segfault if pointer is NULL? If it is compiler specific, I'd like to know how it is in GCC.
| No, because ofshort circuit evaluation.
If the LHS isfalse, then the RHS won't be evaluated. Therefore, if it's aNULLpointer, it will never hit the RHS and attempt to dereference it.
|
I need to know what it means when a function has avoid *parameter. For example:
```
function(void * param){}
```
| It is a function that receives avoid*. This may be used to pass any kind of pointer in C.
A good example is thepthread_createfunction, and the pthread start routine.
Note, however, that if no return type is specified, it defaults to return anint, which it does not in your example.
|
I need to encode a few instructions like
```
mov eax, edx
inc edx
```
to the corresponding x86_64 opcodes. Is there any library (not an entire asm compiler) to accomplish that easily?
| You could take open sourceFASMorNASMand use their parser.
|
I have a code, that is split into multiple files, and which has to use a lot of constant strings(hundreds), and many of them have to be accessed from functions located in several files, what is the most convenient way to do this?
| You can make a header called e.g.,global.hand put your constants on it and include where the constants is needed(in fact,you will include for context,because you need to useinclude guardsfor avoid redefinition error)
|
I want to block the user to backup files to optical discs, so I have to determine if a CDROM drive is writable.
How to do under Windows?
| The drive index (0 = A, 1 = B, etc) for the Windows CD burner can be found in the registry atHKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\CD Burning\DriveIndex.
|
I was going through the linux kernel sources and found this function definition.
```
function(struct net * const *pnet)
```
Can somebody explain what does this mean. Is it a net* or net** or const net* or const net**?
Thanks
| pnet is a pointer to a const point to a struct net (in a case like this, you just read from right to left from the name of the variable to the name of the type, reading*as "pointer).
|
I write a server/client TCP application in C .Many clients can be connected to the server at the same time. How can a client be disconnected after 10 seconds he called close()?
| Callcloseon the socket 10 seconds after youacceptit.
|
I recently updated Ubuntu from 10.04 to 12.04 this changed the linux Kernel from 2.6.35-30-server to 3.0.0-29-server. After the update I am currently getting an error when I am compiling my driver code.
error: implicit declaration of function 'semaphore_init' [-Werror=implict-function-declaration].
How do I resolve this ?
| Unlesssemaphore_initis a function of your own making, I think you'll wantsema_initinstead.
|
This question already has answers here:Closed10 years ago.
Possible Duplicate:What does “-1L” mean in C?
What does "0L", "1L" mean in C ?
How is it different from "0" and "1" ?
Is there other literals than "L" with similar function in C ?
| It's an integer constant that has along inttype instead ofint.
C11, § 6.4.4.1 Integer constants #1long-suffix: one oflL
|
What is the meaning of:
```
printf("%c", **++argv);
```
in a C command line program?
| Print the first character of the first argument passed. i.e.argv[1][0]
argvis a pointer to pointer passed tomain().
**++argv:
First it is incremented (due to pre-increment) to point to the next pointer which isargv[1]and then dereferences that pointer to pointer using which isargv[1][0].
|
Where do i find the definition/body of the printf/scanf & other similar predefined commonly used functions (getch, clrsr ...etc) of "Borland C" ?
| You cannot.. You can just see the prototype ofprintf/scanfin the header file<stdio.h>
You can find it in the standard library which comes with whatever compiler you are using..
|
What is the meaning of:
```
printf("%c", **++argv);
```
in a C command line program?
| Print the first character of the first argument passed. i.e.argv[1][0]
argvis a pointer to pointer passed tomain().
**++argv:
First it is incremented (due to pre-increment) to point to the next pointer which isargv[1]and then dereferences that pointer to pointer using which isargv[1][0].
|
Where do i find the definition/body of the printf/scanf & other similar predefined commonly used functions (getch, clrsr ...etc) of "Borland C" ?
| You cannot.. You can just see the prototype ofprintf/scanfin the header file<stdio.h>
You can find it in the standard library which comes with whatever compiler you are using..
|
Which roles are used when i call a function with pointer argument unless declare the function before? I know that float are promoted to double and that are executed the integral promotion, but what happens at the pointers?
| Nothing. Default argument promotions don't apply to arguments of pointer type so they are left unchanged in type and value.
|
I want to store 5 names without wasting 1byte , so how can allocate memory using malloc
| That's for all practical purposesimpossible,mallocwill more often than not return blocks of memory bigger than requested.
|
This question already has answers here:Closed10 years ago.
Possible Duplicate:Passing two-dimensional array via pointer
```
int table[20][20];
int** table1 = table;
int a;
table[0][0] = 4;
a = table1[0][0];
```
the last line gives me Access violation, and i dont get it ..
thanks in advance!
| The short answer is that a pointer to a pointer is not the same as an array of arrays.
|
I'm looking for a very simple implementation of RSA in C. I need to place it in a DSP, so I'd like to use something very thin and straightforward.
Nonetheless, I just found only examples with little numbers (int or long) while I need to implement RSA at least at 1024 bits, so I also have to cope with large numbers.
Can you point me to some libraries or examples for this?
| TheLibTomCryptand related projects are very clean and understandable.
|
I'm looking for a very simple implementation of RSA in C. I need to place it in a DSP, so I'd like to use something very thin and straightforward.
Nonetheless, I just found only examples with little numbers (int or long) while I need to implement RSA at least at 1024 bits, so I also have to cope with large numbers.
Can you point me to some libraries or examples for this?
| TheLibTomCryptand related projects are very clean and understandable.
|
Is it possible to usescanfin order to give a value to a macro substitution calledSIZE(#define SIZE) but without saving the value that came withscanfin another variable?
| Macros are evaluated at pre-compilation by pre-compilerscanfis evaluated by the compiler. Compiler doesn't understand macros. So no.
|
Do standard C library implementations, especiallyglibc(the GNU C Library) provide linked lists, stack et al. data structures, or do we have to roll our own?
Thanks.
| The C Standard does not provide data structures like linked list and stack.Some compiler implementations might provide their own versions but their usage will be non portable across different compilers.
So Yes, You have to write your own.
|
First apologize for asking this dumb question:
How to call this function in c (GNU C)
```
char *ftoa(float f, char *buf, int places)
```
| This is how you call it:
```
int decimal_places = 10;
char* result = malloc(decimal_places + 1);
ftoa(SOME_FLOAT_VALUE, result, decimal_places);
```
The function returns itsbufargument. As always, don't forget to free() theresultstring when you're done with it.
|
With:
```
char *x = malloc(1024);
strcpy(x, "asdf");
x = strdup(x);
free(x); // OK
free(x); // Segfault
```
If I just free it once, will I still be leaking? And if so, how to avoid it?
| You leak memory because you forget the first pointer. Do it like this:
```
char * x = malloc(1024);
strcpy(x, "asdf");
char * y = strdup(x);
free(x);
free(y);
```
|
Is it possible to usescanfin order to give a value to a macro substitution calledSIZE(#define SIZE) but without saving the value that came withscanfin another variable?
| Macros are evaluated at pre-compilation by pre-compilerscanfis evaluated by the compiler. Compiler doesn't understand macros. So no.
|
Do standard C library implementations, especiallyglibc(the GNU C Library) provide linked lists, stack et al. data structures, or do we have to roll our own?
Thanks.
| The C Standard does not provide data structures like linked list and stack.Some compiler implementations might provide their own versions but their usage will be non portable across different compilers.
So Yes, You have to write your own.
|
First apologize for asking this dumb question:
How to call this function in c (GNU C)
```
char *ftoa(float f, char *buf, int places)
```
| This is how you call it:
```
int decimal_places = 10;
char* result = malloc(decimal_places + 1);
ftoa(SOME_FLOAT_VALUE, result, decimal_places);
```
The function returns itsbufargument. As always, don't forget to free() theresultstring when you're done with it.
|
With:
```
char *x = malloc(1024);
strcpy(x, "asdf");
x = strdup(x);
free(x); // OK
free(x); // Segfault
```
If I just free it once, will I still be leaking? And if so, how to avoid it?
| You leak memory because you forget the first pointer. Do it like this:
```
char * x = malloc(1024);
strcpy(x, "asdf");
char * y = strdup(x);
free(x);
free(y);
```
|
This question already has answers here:Closed10 years ago.
Possible Duplicate:C/C++ line number
I want to display the line number where the printf is triggered?
It may look like this:
```
printf("the line number is: %d",SOME_LIBC_MACRO);
```
How to do it?
| Use the__LINE__macro
```
printf("the line number is: %d", __LINE__);
```
Lists of other pre-defined macros are available forGCCandVisual Studio
|
I printed sizeof(struct tm) in C using sizeof() operator it gives me 44 bytes.But in man page of ctime it has 9 int variables for time.then its size should be 36. How it is giving 44?
| http://linux.die.net/man/3/ctime
The glibc version of struct tm has additional fieldslong tm_gmtoff; /* Seconds east of UTC */
const char *tm_zone; /* Timezone abbreviation */
That's where you extra bytes come from (probably).
|
I want to add the ascii values of a string, say "hello".
What is the best way to do that in c? is There a way without looping the string?
| Of course, you can do it without looping:
```
#include <stdio.h>
int sum(const char *s) { return *s == 0 ? 0 : *s + sum(s + 1); }
int main()
{
printf("%d\n", sum("hello"));
return 0;
}
```
|
This question already has answers here:Closed10 years ago.
Possible Duplicate:C/C++ line number
I want to display the line number where the printf is triggered?
It may look like this:
```
printf("the line number is: %d",SOME_LIBC_MACRO);
```
How to do it?
| Use the__LINE__macro
```
printf("the line number is: %d", __LINE__);
```
Lists of other pre-defined macros are available forGCCandVisual Studio
|
I printed sizeof(struct tm) in C using sizeof() operator it gives me 44 bytes.But in man page of ctime it has 9 int variables for time.then its size should be 36. How it is giving 44?
| http://linux.die.net/man/3/ctime
The glibc version of struct tm has additional fieldslong tm_gmtoff; /* Seconds east of UTC */
const char *tm_zone; /* Timezone abbreviation */
That's where you extra bytes come from (probably).
|
I'm a beginner in C.
Is there any datatype for dates?In C we have for working with time, is there one for dates too?How can I calculate difference between two dates?
| Yes,the standard libraryC Time Librarycontains structures and functions you want.You can usestruct tmto store date anddifftimeto get the difference.
|
I have a data structure:
```
typedef struct{
int a;
int b;
int c;
}EVENTS;
EVENTS newone[20];
```
Then I use newone somewhere.
Now, I want to reset all values of newone[20] to 0.
Is there a short way to do this?
Thanks
| The shortest way is to usememset
```
memset(newone, 0, sizeof(newone));
```
|
I have tried googling this but all I get is results on how to compile a basic program.
Is it possible to compile code to a specific C++ standard using Clang++ and G++ by specifying that code should be compiled to say, C89, C99, C++98, etc?
| You can use the -std flag. For example, to compile to C99, use-std=c99
The documentation for it ishere
|
I know the meaning of this statement
```
scanf("%d",&x);
```
But what does this statement do
```
scanf("%2d",&x);
```
I tried searching for this, but could not find an answer. I want to know what happens internally also.
| That's two digits number:
```
int n = 0;
scanf ("%2d", &n);
printf ("-> %d\n", n);
```
12
-> 12
88657
-> 88
|
This question already has an answer here:Closed10 years ago.
Possible Duplicate:What is the rationale in allowing `?` to be escaped?
If I can do this:
```
string i = "'";
```
Why do this:
```
string i = "\'";
```
| You need it if you want a character literal:
```
char apos = '\'';
```
|
I know the meaning of this statement
```
scanf("%d",&x);
```
But what does this statement do
```
scanf("%2d",&x);
```
I tried searching for this, but could not find an answer. I want to know what happens internally also.
| That's two digits number:
```
int n = 0;
scanf ("%2d", &n);
printf ("-> %d\n", n);
```
12
-> 12
88657
-> 88
|
This question already has an answer here:Closed10 years ago.
Possible Duplicate:What is the rationale in allowing `?` to be escaped?
If I can do this:
```
string i = "'";
```
Why do this:
```
string i = "\'";
```
| You need it if you want a character literal:
```
char apos = '\'';
```
|
I am creating a .so file with a C code. I need to link some other .so files to the .so file am creating. how to do it?
I tried this-L{path to file containing library} -l${library name}is it right?
| If your library file is called/path/to/libfile.so, then typically you'd need to specify the following arguments to the linker:
```
-L/path/to -lfile
```
Note that we only include the directory in-L, and omit both thelibprefix and the.sosuffix from-l.
|
In Visual C 2010 how do you do a string comparison to check for equality between a char* and a LPWSTR? For example, do something to the extent of
```
LPWSTR *str;
if (*str == "fileName") //...
```
| I believe the wsccmp function should do what you are looking to do.
http://msdn.microsoft.com/en-us/library/e0z9k731(v=vs.80).aspx
|
I want to copy the screen buffer of the command/powershell window to a text file using C/C++/Powershell.
Is there any way to do it?
| Use the Host console API:-
```
$rec = new-object System.Management.Automation.Host.Rectangle 0,0,($host.ui.rawui.BufferSize.Width - 1),$host.ui.rawui.CursorPosition.Y
$buffer = $host.ui.rawui.GetBufferContents($rec)
```
Write buffer to file using >> or |
|
I wonder whether Timer created with
```
int eloop_register_timeout (unsigned int secs,
unsigned int usecs,
eloop_timeout_handler handler,
void * eloop_data,
void * user_data
)
```
in hostapd runs asynchronously.
| No, the timer is run in the event loop thread when it expires.
|
Which is the plug in I need to install to program C in my eclipse
How I install it?
| You need to install eclipseCDT(C Development Kit). You can choose which compiler you want to use with CDT. You can read morehere.
|
Hello I'm trying to convert a decimal value to a hex using C in order to store it on my variablechar data[]and use the data later for something else. Does any one know how I can do it? I'm new to C
| You can use the%xformat specifier and asprintf. Passdataas the first parameter, and the value to be printed as the last parameter:
```
int value = 12345;
char data[16];
sprintf(data, "%x", value); // This produces 3039
```
Link to ideone.
|
I want a command that will completely ignore a function. Somebody once showed me the command, but I can't find it in the manual.
```
void a()
{
return;
}
#pragma gcc_disable
void a ()
{
return q09w8uifsdf
}
#include <stdio.h>
int main ()
{
a();
}
```
| Umm... you mean this?
```
void a()
{
return;
}
#if 0
void a ()
{
return q09w8uifsdf
}
#endif
#include <stdio.h>
int main ()
{
a();
}
```
|
Which is the plug in I need to install to program C in my eclipse
How I install it?
| You need to install eclipseCDT(C Development Kit). You can choose which compiler you want to use with CDT. You can read morehere.
|
Hello I'm trying to convert a decimal value to a hex using C in order to store it on my variablechar data[]and use the data later for something else. Does any one know how I can do it? I'm new to C
| You can use the%xformat specifier and asprintf. Passdataas the first parameter, and the value to be printed as the last parameter:
```
int value = 12345;
char data[16];
sprintf(data, "%x", value); // This produces 3039
```
Link to ideone.
|
How can I in my make-file use option-std=c99or-std=gnu99to compile my C code?
```
-include ../../../Common/C/Make.cfg
### target ###
TARGET_NAME = myRec
### Objects, sources ###
# C source files
CSRCS = \
myRec.c
LDLIBS ?= -lNBiometrics -lNMedia -lNCore
include ../../../Common/C/Make.rules
```
| You need to set theCFLAGSmakefile variable.
|
I want to change some kernel source files for network stack testing so is there any way to get kernel source code for RHEL6 Enterprise edition and how to apply the changes to get results?
| Herefrom redhat ftp, you may get what you want.
Example:kernel-2.6.32-220.17.1.el6.src.rpm
|
Using
```
int main(int argc, char *argv[])
{
double number1, number2;
char operator;
number1 =atof (argv[0]);
operator =argv[1]; // line 29
number2 =atof (argv[2]);
```
Compiler complains saying
29 warning: assignment makes integer from pointer without a cast
[enabled by default]
| argv[1] is a pointer to char, you can't assign it to a char. either transform operator to char * or try operator = *(argv[1]);
|
Using
```
int main(int argc, char *argv[])
{
double number1, number2;
char operator;
number1 =atof (argv[0]);
operator =argv[1]; // line 29
number2 =atof (argv[2]);
```
Compiler complains saying
29 warning: assignment makes integer from pointer without a cast
[enabled by default]
| argv[1] is a pointer to char, you can't assign it to a char. either transform operator to char * or try operator = *(argv[1]);
|
I need a condition for a do-while loop that means the loop is repeated (asking user to enter data again) until it is an integer number and between 1 and 25.
```
while (!isdigit(data) || data < 1 || data > 25);
```
This just throws out a runtime error and I'm not sure why.
| Try this:
```
do {
/* Read from input and store it in data */
} while( !isdigit(data) || !( data > 1 && data < 25 ) );
```
|
I need a condition for a do-while loop that means the loop is repeated (asking user to enter data again) until it is an integer number and between 1 and 25.
```
while (!isdigit(data) || data < 1 || data > 25);
```
This just throws out a runtime error and I'm not sure why.
| Try this:
```
do {
/* Read from input and store it in data */
} while( !isdigit(data) || !( data > 1 && data < 25 ) );
```
|
I need a condition for a do-while loop that means the loop is repeated (asking user to enter data again) until it is an integer number and between 1 and 25.
```
while (!isdigit(data) || data < 1 || data > 25);
```
This just throws out a runtime error and I'm not sure why.
| Try this:
```
do {
/* Read from input and store it in data */
} while( !isdigit(data) || !( data > 1 && data < 25 ) );
```
|
I declared an array:
char * words[1000] = {NULL};
And now I have a series of forked child processes adding words to that array, but they are not affecting the parent program. How can I change that?
| Hmm, for your edit-case: Dont use fork, use threads, because then everything runs in one address-space...And of course, then use mutexes to protect your words-array...
|
I'm making a Mac OSX program where I need to take a snapshot (image file) the currently active window in Photoshop.
How would I go about this?
| I ended up using Applescript inside Xcode to find photoshop and saving a copy of the current file. Not the best solution but it works.
|
I declared an array:
char * words[1000] = {NULL};
And now I have a series of forked child processes adding words to that array, but they are not affecting the parent program. How can I change that?
| Hmm, for your edit-case: Dont use fork, use threads, because then everything runs in one address-space...And of course, then use mutexes to protect your words-array...
|
I'm making a Mac OSX program where I need to take a snapshot (image file) the currently active window in Photoshop.
How would I go about this?
| I ended up using Applescript inside Xcode to find photoshop and saving a copy of the current file. Not the best solution but it works.
|
I declared an array:
char * words[1000] = {NULL};
And now I have a series of forked child processes adding words to that array, but they are not affecting the parent program. How can I change that?
| Hmm, for your edit-case: Dont use fork, use threads, because then everything runs in one address-space...And of course, then use mutexes to protect your words-array...
|
I'm making a Mac OSX program where I need to take a snapshot (image file) the currently active window in Photoshop.
How would I go about this?
| I ended up using Applescript inside Xcode to find photoshop and saving a copy of the current file. Not the best solution but it works.
|
Specifically I am doing this
```
Word32 x = 18653184;
Word32 y;
Word16 shift = 269;
y = x >> shift;
```
I'd expect the result of this logical shift to be 0, but I am instead getting 2277. How does C define this type of operation?
| Yes, it is undefined behavior, according to section 6.5.7 paragraph 3
... If the value of the right operand is negative or is greater than or equal to the width of the promoted left operand, the behavior is undefined.
|
Specifically I am doing this
```
Word32 x = 18653184;
Word32 y;
Word16 shift = 269;
y = x >> shift;
```
I'd expect the result of this logical shift to be 0, but I am instead getting 2277. How does C define this type of operation?
| Yes, it is undefined behavior, according to section 6.5.7 paragraph 3
... If the value of the right operand is negative or is greater than or equal to the width of the promoted left operand, the behavior is undefined.
|
I'm debugging a thread impersonating a currently logged on user in a Windows service process running underSYSTEMaccount. How could I determine the current impersonation level (as in whetherimpersonationordelegationwas used) either programmatically, or using Visual Studio debugger or other tools?
| Simplest way is via Visual Studio$userpseudo variable.
|
I'm debugging a thread impersonating a currently logged on user in a Windows service process running underSYSTEMaccount. How could I determine the current impersonation level (as in whetherimpersonationordelegationwas used) either programmatically, or using Visual Studio debugger or other tools?
| Simplest way is via Visual Studio$userpseudo variable.
|
With this struct
```
typedef struct tNode_t {
struct tNode_t **a;
} tNode;
```
I want to be able to haveapoint to an array to 5 pointers to tNodes
example main:
```
int main()
{
tNode t;
tNode (*alpha)[5];
t.a = alpha;
}
```
why doesn't this work?
| This defines a pointer to an array of tNodes:
```
tNode (*alpha)[5];
```
This defines an array of pointers to tNodes:
```
tNode *alpha[5];
```
|
when running my code in borland c 3.1 it works fine, but when running it on c-free it crashes at this line:while(ptr1->pright)
{
ptr1=ptr1->pright;
}giving SIGSEGV, any logical reasons?
| You're probably accessing memory outside the bounds of an array or which you didn't allocate. As such, you triggeredundefined behaviour, so pretty much anything can happen, including crashing or evenapparentlyworking fine.
|
when running my code in borland c 3.1 it works fine, but when running it on c-free it crashes at this line:while(ptr1->pright)
{
ptr1=ptr1->pright;
}giving SIGSEGV, any logical reasons?
| You're probably accessing memory outside the bounds of an array or which you didn't allocate. As such, you triggeredundefined behaviour, so pretty much anything can happen, including crashing or evenapparentlyworking fine.
|
when running my code in borland c 3.1 it works fine, but when running it on c-free it crashes at this line:while(ptr1->pright)
{
ptr1=ptr1->pright;
}giving SIGSEGV, any logical reasons?
| You're probably accessing memory outside the bounds of an array or which you didn't allocate. As such, you triggeredundefined behaviour, so pretty much anything can happen, including crashing or evenapparentlyworking fine.
|
How would I make a pointer to:
```
char * values [x];
```
I'm trying to pass an array ofchar *to a pointer from outside the block of code, where x can by anything.
| Pointer to a pointer can do what you want.
```
char ** val ;
```
In the function definition :
```
return_type func(char ** val) {...}
```
In the function call :
```
func(&values)
```
You need to pass the address of the pointer to the function.
|
I have already compilelamefor android as static library.
How can I use lame for convert awavfile tomp3?
What I have to call? There is some tutorial of how use lame as library?
| You can see thisdeveloper.samsung.comtutorial for porting or how we use LAME on Android with JNI
Porting and using LAME MP3 on Android with JNI
|
Is the compound operator '&=' logical or bitwise AND ?
In other words, isa &= bthe same as:
a = a & ba = a && b
| a &= bis using the bitwise AND operator. Think of the+=operation:
```
a += 5;
```
is the same as:
```
a = a + 5;
```
It's just a combination of two operations:&and=.
|
Are there any c compilers for ms-dos that support some C99 features?
I have trouble searching for recent compilers that I can run on my system.
Actually, I need this to have a compiler on my Playbook via Dos Box, while I am away from home and wihout internet access.
| This compiler should work on MSDOS (gcc adapation)
http://personal.ee.surrey.ac.uk/Personal/R.Bowden/C/dos-gcc/index.htm
|
Win32 has the winmm library, which allows joystick events to be captured in the regular event loop (alongside the general window events, keyboard events, and mouse events).
Is there a similar setup in Xlib? Is my only choice to do raw input?
| Sounds like the answer is no (until someone smarter than me comes along and corrects me). I need to do raw input. I have to poll at a reasonable interval and convert deltas into my own events.
|
Win32 has the winmm library, which allows joystick events to be captured in the regular event loop (alongside the general window events, keyboard events, and mouse events).
Is there a similar setup in Xlib? Is my only choice to do raw input?
| Sounds like the answer is no (until someone smarter than me comes along and corrects me). I need to do raw input. I have to poll at a reasonable interval and convert deltas into my own events.
|
I installed GNAT 2012 a while back when I was working with Ada and it came with a version of GCC. I can compile C files from the command prompt using gcc fine, but "make" apparently wasn't included.
How would I go about getting make working? Should I just install the newest version of GCC instead?
| Make is not part of GCC. On Windows, you can useMSYS. It includes make and other useful tools.
|
I installed GNAT 2012 a while back when I was working with Ada and it came with a version of GCC. I can compile C files from the command prompt using gcc fine, but "make" apparently wasn't included.
How would I go about getting make working? Should I just install the newest version of GCC instead?
| Make is not part of GCC. On Windows, you can useMSYS. It includes make and other useful tools.
|
I have problems to jump to an label.
My Code:
```
asm{
keypress:
...
cmp ax,0000
jz keypress
}
```
Borland says: Undefined Label "keypress"
| Try moving the label to outside of the asm block (i.e., just above the "asm{" line). This is per thislinkand thislink.
Also note that evidently you may not be able to jump to a forward label (perhere), but that's of course not your problem in this example.
|
I'm stuck with my code for 20 minutes.
What's wrong with this simple C code?
```
void function (char & reference_to_something) {}
```
error:
```
expected ';' , ',' or ')' before '&' token
```
| C does not have references; C++ does.
|
Is there a way to open a full screen window withSFMLon a 2nd monitor?
| I'm afraid the answer is no. Here's a quote from a different part of that site:
SFML doesn't explicitely manage multiple monitors. As a consequence, you won't be able to choose which monitor a window appears on, and you won't be able to create more than one fullscreen window. This should be improved in a future version.
|
When I include mysql.h in my source file, I get all sorts of syntax errors. I'm using the cygwin gcc compiler and MysQL Windows Connector 6.0.2. I added an image of my IDE. What can I do to fix this?Click here for larger image
| You need to includewinsockright before mysql.
|
If I keep incrementing aCvariable, does it saturate or wrap around?
| For signed integer types, it'sundefinedas to what happens.
For unsigned integer types, it will wrap around (i.e. back to 0).
|
I have a question regarding to reset array in c,
I define a array like this:
```
static int hello[5][6] = {{1,2,3,4,5,6},1,2,3,4,5,6},1,2,3,4,5,6},1,2,3,4,5,6},1,2,3,4,5,6}};
```
then how to reset all the element on each row and line as 0?
| ```
memset (hello, 0, sizeof(hello));
```
|
What do i need to to do to print the contents of a memory provided that it can have null characters in between.
suppose i have an address 0X123.i want to print some 100 characters before this address in the memory and there can be some NULL characters in between and i want to print those NULL characters too.
| Use unformatted output:
```
cout.write(address, count);
```
Or for C:
```
fwrite(address, 1, count, stdout);
```
|
When I include mysql.h in my source file, I get all sorts of syntax errors. I'm using the cygwin gcc compiler and MysQL Windows Connector 6.0.2. I added an image of my IDE. What can I do to fix this?Click here for larger image
| You need to includewinsockright before mysql.
|
If I keep incrementing aCvariable, does it saturate or wrap around?
| For signed integer types, it'sundefinedas to what happens.
For unsigned integer types, it will wrap around (i.e. back to 0).
|
I have a question regarding to reset array in c,
I define a array like this:
```
static int hello[5][6] = {{1,2,3,4,5,6},1,2,3,4,5,6},1,2,3,4,5,6},1,2,3,4,5,6},1,2,3,4,5,6}};
```
then how to reset all the element on each row and line as 0?
| ```
memset (hello, 0, sizeof(hello));
```
|
What do i need to to do to print the contents of a memory provided that it can have null characters in between.
suppose i have an address 0X123.i want to print some 100 characters before this address in the memory and there can be some NULL characters in between and i want to print those NULL characters too.
| Use unformatted output:
```
cout.write(address, count);
```
Or for C:
```
fwrite(address, 1, count, stdout);
```
|
When I include mysql.h in my source file, I get all sorts of syntax errors. I'm using the cygwin gcc compiler and MysQL Windows Connector 6.0.2. I added an image of my IDE. What can I do to fix this?Click here for larger image
| You need to includewinsockright before mysql.
|
If I keep incrementing aCvariable, does it saturate or wrap around?
| For signed integer types, it'sundefinedas to what happens.
For unsigned integer types, it will wrap around (i.e. back to 0).
|
I have a question regarding to reset array in c,
I define a array like this:
```
static int hello[5][6] = {{1,2,3,4,5,6},1,2,3,4,5,6},1,2,3,4,5,6},1,2,3,4,5,6},1,2,3,4,5,6}};
```
then how to reset all the element on each row and line as 0?
| ```
memset (hello, 0, sizeof(hello));
```
|
What do i need to to do to print the contents of a memory provided that it can have null characters in between.
suppose i have an address 0X123.i want to print some 100 characters before this address in the memory and there can be some NULL characters in between and i want to print those NULL characters too.
| Use unformatted output:
```
cout.write(address, count);
```
Or for C:
```
fwrite(address, 1, count, stdout);
```
|
This question already has answers here:Closed10 years ago.
Possible Duplicate:Recommended way to initialize srand?
I have the following problem when using srand() in c.
I call srand(time(NULL))in a loop, but the loopfinishes before 1sec and every time I call the rand() I get the same value.
How can I solve this?
| Why are you callingsrandin a loop? Just call it once at the start of your program and then callrandany number of times.
|
When is it appropriate to include a type conversion in a symbolic constant/macro, like this:#define MIN_BUF_SIZE ((size_t) 256)Is it a good way to make it behave more like a real variable, with type checking?When is it appropriate to use theLorU(orLL) suffixes:#define NBULLETS 8U
#define SEEK_TO 150L
| You need to do it any time the default type isn't appropriate. That's it.
|
I have three ints.
Fx:20121121
I want to convert them into a single int20121121
Can this be done?
I have tried messing around withatoi()without results.
| Well, to answer directly the question that you asked, you would do it like this:
```
int combined = year*10000 + month*100 + day;
```
But your approach is quite possibly not the best solution to your actual problem.
|
I have three ints.
Fx:20121121
I want to convert them into a single int20121121
Can this be done?
I have tried messing around withatoi()without results.
| Well, to answer directly the question that you asked, you would do it like this:
```
int combined = year*10000 + month*100 + day;
```
But your approach is quite possibly not the best solution to your actual problem.
|
I need to parse a HTTP request in C. I've been previously using std::regex for C++ but now I have to use C. What would be the best method to parse a HTTP request with C?
| Apache recommends cgic, you can find it athttp://www.boutell.com/cgic/and its very simple to use
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.