question
stringlengths 24
425
| answer
stringlengths 5
405
|
---|---|
hi there i can compare people birthday in format YYYY-MM-DD with string (strcmp) functions. but i need compare todays date with person's birthday to display if his/her birthday is in 7 days or not_?. i searched "time.h" library but couldn't managed it. i appreciated if you can help.
| I would usedifftimeon thetime_tvalues and compare against the number of seconds in a week...
|
What exactly does the below statement do?
```
const char *string
*string - '0'
```
Thanks!
| It subtracts the value of the character'0'from the character pointed to bystring, turning it into a numerical value. So for example the character'9'will be turned into the integer9.
|
I have a sample problem withw=1,y=7,z=0,x = ~(w && y) | y;and the solution isx = -1, but I can't figure out why?
Here is my thought process:(w && y) = (1 && 7) = 1~11 in bits is0000 0001~1 in bits is1111 1110
Not sure what to do from here.
| The last step is a bitwise OR so you get:
```
1111 1110 | 0000 0111 = 1111 1111
```
which is -1.
|
Is there a way to find the parameters passes to the kernel (/proc/cmdline) at boot time without reading any files in proc? I might have a process that needs to read the boot parameters before /proc is mounted.
| It seems the kernel passes anything on the boot line as a arg to init- unless there is a ' = ' or a ' . '
Passing Linux boot opts to Init
|
```
main()
{
char *x="girl";
int n,i;
n=strlen(x);
*x=x[n];
for(i=0;i<n;i++)
{
printf("%s \n",x);
x++;
}
}
```
What is the output?Please explain the output.......................o/p is :
```
irl
rl
l
```
| The output is undefined behaviour. You modified a string literal.
|
Where i can find documentation about registers which assembly must preserve when a C function is called?
| What you want is your system's C Application Binary Interface. Google for "C ABI" and your architecture, and you'll find it. For example,hereis one for sparc andhereis the relevant bit for AVRs.
|
Are there existing algorithm visualization tool for C programs? like visualizing an execution of a C program through animated execution stack.
| I recommenddddfor fancy GUI debugging visualizations. It visualizes all the data structures and makes pretty graphs and gives you access to your regular debugger.
|
Where i can find documentation about registers which assembly must preserve when a C function is called?
| What you want is your system's C Application Binary Interface. Google for "C ABI" and your architecture, and you'll find it. For example,hereis one for sparc andhereis the relevant bit for AVRs.
|
Are there existing algorithm visualization tool for C programs? like visualizing an execution of a C program through animated execution stack.
| I recommenddddfor fancy GUI debugging visualizations. It visualizes all the data structures and makes pretty graphs and gives you access to your regular debugger.
|
I am new to C and I have this code:
```
f = fopen( argv[1], "rb" );
fseek( f, 64, SEEK_SET );
fpos_t pos;
fgetpos (f, &pos);
printf("%x", pos);
```
However, this returns 40, even though it's supposed to be returning 64. What am i doing wrong?
| You are outputting 64 in hex format,"%x". Since 64=0x40, the mystery is solved!
|
The below fails to compile:
```
typedef int arr[10];
int main(void) {
return sizeof arr;
}
sizeof.c:3: error: expected expression before ‘arr’
```
but if I change it to
```
sizeof(arr);
```
everything is fine. Why?
| According to 6.5.3, there are two forms forsizeofas the following:
```
sizeof unary-expression
sizeof ( type-name )
```
Sincearrin your code is atype-name, it has to be parenthesized.
|
We're running a Linux server with Microsoft SQL Server for the database. Are there any good (preferably open source) c libraries that we could use other than FreeTDS?
Thank you
| Not really. Sybase has some client libraries, but they only work for older versions of MS SQL Server (since it is a derivative of Sybase SQL Server).
|
Can anyone recommend a good library I could use on Linux to watermark videos? I want to overlay a watermark at several different positions in my videos, fade them in randomly and with different colors and opacity.
| Have you triedffmpeg? That's a very good tool for video related stuff. Also for watermarking you can try thislink.
|
I am wondering if there is an equivalent to C's fputc in PHP?
I am trying to do the following C code in PHP:
```
fputc(0x10, fp);
```
more information on fputc:http://en.wikipedia.org/wiki/C_file_input/output#Writing_to_a_stream_using_fputc
Thanks
| You can write the character code directly to the file:
```
fputs($fp, "\x10");
// or
fputs($fp, chr(16));
// or
fputs($fp, chr(hexdec(10));
```
|
Let's say I've got that:
```
char *p = NULL;
```
I'm sure this one would be a problem as I'd be dereferencing aNULLpointer:
```
*p = 16;
```
On the other hand, I think this one would be OK for I'd be getting the address of *p which is notNULLitself:
```
char **pp = &p;
```
Am I right in both cases?
| Yes you are. Although the value of p is NULL, it still has a valid address, so you may pass its reference.
|
I'm having a problem with using the automatic formatting in Eclipse CDT. For the most part it works great but it seems to insist on putting the semicolons after macro calls on a separate line.
Is this a bug or did I mischeck a combination of formatting settings which lead to this?
| The problem has been fixed in later versions of Eclipse CDT. Just try to download later version of Eclipse.
|
I hope that this makes sense.... is there a way to get xCode to use the makefile system for building C programs??
| Yes - set up an "external build system" project.
|
is it possible in java to have a C like syntax for this:
```
int counter = 10;
while(counter){
System.out.println(counter--);
}
```
In C it is working very well to count until the counter is 0... do i really have to write
```
int counter = 10;
while(counter!=0){
System.out.println(counter--);
}
```
?
| No, java requires abooleanin awhilecondition.
|
Does anyone know, how can we verify whether an allocated space is successfully freed? In the manual page, it says that "free() returns no value".
| There are three possible cases:
```
free( NULL ); // does nothing, so always works
free( malloc(42) ); // does something, always works
free( 666 ); // undefined behaviour - returned value would be meaningless
```
So there is no case where testingfree()has a point.
|
Hi i would like to convert 0x49 and 0x83 from C++ to C#.
May i know what does this 0x49 represent in c# character?
Also, what does 83 represent in character?
I have searching through google but found no answer for this. I would appreciate it there is a chart outthere list out all the ASCII code representing the characters meaning.
| Have a lookhere. But ascii is ascii.. there are no differences between C++ and C#
|
I am trying to make a calculator in C or Objective-C that accepts a string along the lines of
```
8/2+4(3*9)^2
```
and returns the answer 2920. I would prefer not to use a generator like Lex or Yacc, so I want to code it from the ground up. How should I go about doing this? Other than the Dragon book, are there any recommended texts that cover this subject matter?
| Dave DeLong'sDDMathParserclass may save you a lot of time and trouble.
|
If I have a an array ofints, how could I directly edit eachint?
```
int i = arr + 1; // Getting the integer in pos 1
```
iis just a copy, correct? If I seti = 4, thenarr + 1would still be1.
Would this work?
```
int *i = &(arr + 1);
*i = 4;
```
| You should use the array operators:
```
int i = arr[1];
arr[1] = 4;
```
|
Hi i would like to convert 0x49 and 0x83 from C++ to C#.
May i know what does this 0x49 represent in c# character?
Also, what does 83 represent in character?
I have searching through google but found no answer for this. I would appreciate it there is a chart outthere list out all the ASCII code representing the characters meaning.
| Have a lookhere. But ascii is ascii.. there are no differences between C++ and C#
|
I am trying to make a calculator in C or Objective-C that accepts a string along the lines of
```
8/2+4(3*9)^2
```
and returns the answer 2920. I would prefer not to use a generator like Lex or Yacc, so I want to code it from the ground up. How should I go about doing this? Other than the Dragon book, are there any recommended texts that cover this subject matter?
| Dave DeLong'sDDMathParserclass may save you a lot of time and trouble.
|
If I have a an array ofints, how could I directly edit eachint?
```
int i = arr + 1; // Getting the integer in pos 1
```
iis just a copy, correct? If I seti = 4, thenarr + 1would still be1.
Would this work?
```
int *i = &(arr + 1);
*i = 4;
```
| You should use the array operators:
```
int i = arr[1];
arr[1] = 4;
```
|
Can anyone give me an example code for a tool window (with pixel dimensions) for the Win32 API?
Thanks
| Tool windows are just windows with the WS_EX_TOOLWINDOW extended style:
```
hWnd = CreateWindowEx(WS_EX_TOOLWINDOW, szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, 100, 100, 500, 400, NULL, NULL, hInstance, NULL);
```
Note you need to use CreateWindow*Ex* to use extended styles. The above is a 500x400 window at 100,100 on the screen.
|
I need to parse a document in C language. I was about to use the strtok function but I don't know if it's the best method or if just a token system is enough (searching for \n, space etc).
The structure of each line of the document is : element \n element "x".
thanks :-)
| Token system if fine,strtokis just an implementation of that. However, you're better off with usingstrtok_rwhich does not keep any internal state outside control of your program.
|
How can I add a new libc function and also call it from C programs? The new function is a not a wrapper to any kernel level system calls. Its function will be done in user space.
| Put it in its own library file and link it with-llibrary_name_here. The only things that belong in libc are already there (along with plenty of things that don't belong there).
|
For the following piece of code:
```
#include<stdlib.h>
#include<stdio.h>
int main()
{
int x;
x = rand()%100;
printf("The Random Number is: %i", x);
return 0;
}
```
It always seems to print the random number as 83. Why is this?
| Mostrandom number generatorsare repeatable. You need to seed the generator before using it which you typically do using the system time.
```
#include <time.h>
srand(time(NULL));
```
|
I'm trying to clear all stored cookies in Libcurl (version 7.21.6) but
nothing really seems to work.
What command should I use?
I'm using the C-binding version.
Thanks.
| You can't "clear" a cookie file (on disk) with libcurl. Just remove it from the file system with a normal system function such as unlink() or zero it with truncate().
You can clear all cookies libcurl knows about in memory with CURLOPT_COOKIELIST "ALL".
|
I have following code,
```
char * segbase_char = (char*)segbase;
```
As debugged in gdb, it prints
```
segbase_char = 0x80e2da8
segbase = 0xb7ffd000
```
Any ideas?
| It is possible that optimisation has resulted in code being moved around, such that the load ofsegbase_charhas been delayed. Try compiling with a lower level of optimisation enabled.
|
How to Create NodeJS equivalent for the below simple C code?
```
int main(int argc, char *argv[]) {
if (fork()) {
printf("I'm parent %d", getpid());
printf("From parent : %d", 1+1);
} else {
printf("I'm child %d", getpid());
printf("From child : %d", 10+20);
}
return 0;
}
```
| Check outChild Processesin theNodeJS docs. Then check outForeveras an example of how to use them.
|
I wrote some simple program
```
int main(){
printf("hello word!");
return 0;
}
```
I compiled it usinggcc -o hello hello.c(no errors)
but when I run itin terminalusing./helloI see nothing, why? thanks in advance
| Could be the missing newline, so that the output is mangled with the next prompt.
Try:
```
printf("hello world\n");
```
this version also uses a more conventional message.
|
when i use read system call, the buffer that i provide in the second argument, where the data
from reading are supposed to get stored, gets overwritten right!?
thanks,
Nikos
| Yes, that is the point ofread(), to fill (=overwrite) the buffer with the content read from the file.
|
Can a CFMutableArrayRef store simple integer values? Or must I wrap them like with NSMutableArray (which is basically the same beast at runtime)?
| CFMutableArrayand its toll-free bridged siblingNSMutableArraywill only allow a pointer value to be stored inside of it.
|
1)can we define a void pointer?such asvoid * pointer;is it allowed in C? what is a void pointer?2) I always hear about Global Variable, but I do not know how to define Global Variable, I mean where to define a Global Variable? in the beginning of a file or what?
| Yes. A void pointer is a pointer to memory where we have not specified what type is at that memory location.Define them outside of any function or class.
|
How to Create NodeJS equivalent for the below simple C code?
```
int main(int argc, char *argv[]) {
if (fork()) {
printf("I'm parent %d", getpid());
printf("From parent : %d", 1+1);
} else {
printf("I'm child %d", getpid());
printf("From child : %d", 10+20);
}
return 0;
}
```
| Check outChild Processesin theNodeJS docs. Then check outForeveras an example of how to use them.
|
I wrote some simple program
```
int main(){
printf("hello word!");
return 0;
}
```
I compiled it usinggcc -o hello hello.c(no errors)
but when I run itin terminalusing./helloI see nothing, why? thanks in advance
| Could be the missing newline, so that the output is mangled with the next prompt.
Try:
```
printf("hello world\n");
```
this version also uses a more conventional message.
|
when i use read system call, the buffer that i provide in the second argument, where the data
from reading are supposed to get stored, gets overwritten right!?
thanks,
Nikos
| Yes, that is the point ofread(), to fill (=overwrite) the buffer with the content read from the file.
|
Can a CFMutableArrayRef store simple integer values? Or must I wrap them like with NSMutableArray (which is basically the same beast at runtime)?
| CFMutableArrayand its toll-free bridged siblingNSMutableArraywill only allow a pointer value to be stored inside of it.
|
Can a CFMutableArrayRef store simple integer values? Or must I wrap them like with NSMutableArray (which is basically the same beast at runtime)?
| CFMutableArrayand its toll-free bridged siblingNSMutableArraywill only allow a pointer value to be stored inside of it.
|
I'm learning C, but I do not understand this:
```
#define square(x) x*x
a = square(2+3) //a = 11
```
When this is run, why doesaend up being11?
| It expands to2+3*2+3, which is equivalent to2+(3*2)+3. Use parentheses to fix it:
```
#define square(x) ((x)*(x))
```
Now try it withsquare(x++)and you'll run into more problems (undefined behavior). Avoid doing this as a macro if you can.
|
what_if_var[0].price(type ischar [10]) has the value of "$15555.665". Is there is anyway to remove "$" from the value (like "15555.665") and convert the value into double?
| If you always know that the'$'is going to be the first character, you could just try:
```
double num = strtod (what_if_var[0].price + 1, NULL);
```
|
Almost every c/c++ open source project I see ships with it aconfigurefile.
But in our own c/c++ project I haven't seen this file so far,
when is it needed?
| I think you are speaking about configure script which is used, whenautotoolsare used to build the project.
The main purpose of theconfigurefile is to generateMakefilesappropriate to your system configuration and to check various preconditions (installed libs, for example).
|
I have a hex value stored in a two byte array:
```
unsigned char hex[2] = {0x02, 0x00};
```
How can I convert this to a decimal value?
| You can use (bitwise operation)
int b = (hex[0] << 8) | hex[1];
or (simple math)
int b = (hex[0] * 0x100) + hex[1];
|
How does 1.000(base2) x 2^-1 + (-0.111(base2) x 2^-1) = .001(base2) x 2^-1?
To add binary numbers don't you simply just add? I'm not seeing how the addition works..
| I'm not sure what you mean when you ask "don't you simply just add?", but the math is correct. It is basically in base-2 scientific notation.
```
1.000(base2) x 2^-1 = 0.100(base2)
-0.111(base2) x 2^-1 = -0.0111(base2)
0.100 + (-0.0111) = 0.0001
0.0001 = 0.001(base2) x 2^-1
```
|
i'm practicing c and looking to use visual studio. but can I write console C programs and debug it step by step? (i use debug for understading algorithms step by step)
thank you.
| Yes, you can. Start off with the c++ version (if you are using Express), it supports c as well.
Visual Studio has a very good debugger and will allow you to step through your code.
|
How can I make it so my window never gets any smaller than x,y? Which WINAPI function can do this?
Thanks
| You reply toWM_GETMINMAXINFOand fill in the structure with your limits.
|
I want to find the size of file on disk on linux OS .
I know command to do so:
du -s -h
Is there any way to find it using c/c++ code ?
| Yes, use thestat(2)system call:
```
#include <sys/stat.h>
...
struct stat statbuf;
if (stat("file.dat", &statbuf) == -1) {
/* check the value of errno */
}
printf("%9jd", (intmax_t) statbuf.st_size);
```
|
I am reading a file of integers. I want to save integers from each line to a new array. For this I want to detect a new line of a file. If anybody knows this please help.
The file to be read is as follows
```
1 2 4 5 6
7 3 2 5
8 3
9 7 6 2
```
| Why not usefgets()to get one line at a time from the file? You can then usesscanf()instead offscanf()to extract the integers.
|
I have a hex value stored in a two byte array:
```
unsigned char hex[2] = {0x02, 0x00};
```
How can I convert this to a decimal value?
| You can use (bitwise operation)
int b = (hex[0] << 8) | hex[1];
or (simple math)
int b = (hex[0] * 0x100) + hex[1];
|
I have a check in my program to see if the user supplies the right amount of command line arguments. If they do not, I print a usage message and then exit the program.
However I'm not sure if I should exit with EXIT_SUCCESS or EXIT_FAILURE - it appears that they both have some merit in terms of their english meaning. Is there an important distinction? What should I do?
| I personally useEXIT_FAILURE, since it's not a normal usage of your program.
|
On my Linux box it shows up as^A,CTRL-Awhen ivithe file. While writing a C program, how should i reference it? How can i find out a numeric value of it?
| Control characters are 0x40 less than their character.Ais65, so^Ais1.
|
After havingdownloadeda Linux Man Page Viewer, I am not seeing the actual man page when hovering over a function.
Should i enable it somehow? Is where a menu item i should be using?
Please advise
| Looks like it requiresCDT5.0.1 and depending on the version of Eclipse you have installed it may not be included.
What Eclipse package do you have installed?
|
The readln reads until the end of line (enter pressed) with spaces and everything,
I would like something like that but for ansi c (not c++ and need to be for linux and windows)
I know that I can make a function that reads every char until the enter pressed but If there is anything cooler it would be great =D
Thanks!
| Fromherethere is fgets that does this.
|
I would like to store 4 char (4 bytes) into an unsigned int.
| You need to shift the bits of each char over, then OR combine them into the int:
```
unsigned int final = 0;
final |= ( data[0] << 24 );
final |= ( data[1] << 16 );
final |= ( data[2] << 8 );
final |= ( data[3] );
```
That uses an array of chars, but it's the same principle no matter how the data is coming in. (I think I got the shifts right)
|
how to count number of occurrences of 1 in a 8 bit string. such as 10110001.
bit string is taken from user. like 10110001
what type of array should be used to store this bit string in c?
| Short and simple. Usestd::bitset(C++)
```
#include <iostream>
#include <bitset>
int main()
{
std::bitset<8> mybitstring;
std::cin >> mybitstring;
std::cout << mybitstring.count(); // returns the number of set bits
}
```
Online Test at Ideone
|
The matrix X is:
```
aa bb cc
dd ee ff
gg hh ii
```
and can be indexed as X[0][1]
my question is how to represent a string matrix in C?
I know char ***matrix, but I don't know the details
| A string is represented in C as an array of chars, so actually this is a three-dimensional matrix:
```
char string_matrix[ROWS][COLUMNS][STRING_LENGTH]
```
or
```
char*** string_matrix
```
|
How can I write afor/whileloop inside a#definedirective in C?
| You're probably looking for\to continue a macro definition across several lines:
```
#define LOOP(start, end) \
for (int i = (start); i < (end); i++) { \
printf("%d\n", i); \
}
```
|
How can I compile my C source files without needing to put amainfunction within them?
I get an error for the.cfiles that have no main function and don't want to have to add the main function just for compilation.
| On GCC, the-cswitch is what you want.
-cmeans "compile, don't link", and you get aname.ooutput file.
|
The matrix X is:
```
aa bb cc
dd ee ff
gg hh ii
```
and can be indexed as X[0][1]
my question is how to represent a string matrix in C?
I know char ***matrix, but I don't know the details
| A string is represented in C as an array of chars, so actually this is a three-dimensional matrix:
```
char string_matrix[ROWS][COLUMNS][STRING_LENGTH]
```
or
```
char*** string_matrix
```
|
How can I write afor/whileloop inside a#definedirective in C?
| You're probably looking for\to continue a macro definition across several lines:
```
#define LOOP(start, end) \
for (int i = (start); i < (end); i++) { \
printf("%d\n", i); \
}
```
|
OK, I have read about CreateFile, ReadFile and WriteFile and I know how to use these. But I could not find any tutorial or guide with an example to use them properly.
How do I handle files?
I want to learn about:
Read strings from file.Write strings to file.
How does one do that?
| Here is an example:
http://www.gamedev.net/page/resources/_/reference/programming/platform-specific/windows/file-io-in-visual-c-r707
|
What does it mean to say that a function (e.g. modular multiplication,sine) is implemented in hardware as opposed to software?
| Implemented in hardware means the electrical circuit (through logical gates and so) can perform the operation.
For example, in the ALU the processor is physically able to add one byte to another.
Implemented in software are operations that usually are very complex combinations of basic implemented in hardware functions.
|
AFAIK, neither C99 nor C++ standards are aware of shared libraries. Why is that?
EDIT: What is a good practice of writing shared libs without duplicating Linux/Windows versions?
Thanks.
| Because a shared library is a feature of the OS.
Nothing to do with any particular language.
|
Very quick question. I want to copy & paste textual data into the source code from the separate file usingincludedirective.
Is it legal?
```
struct Record; // collection of data fields
Record rec = { #include "some_big_record.txt" };
int numbers[] = { #include "some_long_sequence_of_numbers.txt" };
```
It works on my box (GCC), but is it portable?
| This is portable:
```
Record rec = {
#include "some_big_record.txt"
};
```
|
How to detect at compile time if I'm using gcc or icc?
(I was quite puzzled to find out that icc defines__GNUC__-- and even__GNUC_MINOR__and__GNUC_PATCHLEVEL__! why?)
| We use
```
#ifdef __INTEL_COMPILER
```
to spliticcoff, assuminggccas a default.
|
I'm a new in both C and Python. These days, I'm learning to embed Python in C. As I am calling Python functions from C, I'd like to know, how can we pass a C structure to Python?
thanks alot in advance!
| The cleanest thing to do is probably tocreate a new typeand implementtp_getattr, either returning the appropriate member of the struct or raising an exception depending on the argument passed.
|
I want to read a string through keyboard to avoid buffer overflow. When i usedfgets(text,30,stdin), it reads but it also reads '\n' character. But i don't want to read '\n' character.
| ```
char s[30];
scanf("%30[^\n]", s);
```
a little explain:
%30[^\n]
30which means read at most 30 chars,[^\n]which means read any char except '\n'.
|
In my programfprintf()returns -1, which indicates an error. How can I find out what actual error was?
| ```
#include <errno.h>
#include <string.h>
...
rc = fprintf(...)
if (rc < 0)
printf("errno=%d, err_msg=\"%s\"\n", errno,strerror(errno))
```
|
Why 2[a] can be compiled if only declare int a[3] in C.
```
1 #include <stdio.h>
2
3 int main(int argc, char **argv)
4 {
5 int a[3] = {1, 2, 3};
6 printf("a[2] is: %d\n", a[2]);
7 printf("2[a] is: %d\n", 2[a]);
8
9 return 0;
10 }
```
And the output both 3, how to explain it?
| Becausea[2]is just syntactic sugar for*(a+2), which is the same as*(2+a)or2[a].
|
Very quick question. I want to copy & paste textual data into the source code from the separate file usingincludedirective.
Is it legal?
```
struct Record; // collection of data fields
Record rec = { #include "some_big_record.txt" };
int numbers[] = { #include "some_long_sequence_of_numbers.txt" };
```
It works on my box (GCC), but is it portable?
| This is portable:
```
Record rec = {
#include "some_big_record.txt"
};
```
|
How to detect at compile time if I'm using gcc or icc?
(I was quite puzzled to find out that icc defines__GNUC__-- and even__GNUC_MINOR__and__GNUC_PATCHLEVEL__! why?)
| We use
```
#ifdef __INTEL_COMPILER
```
to spliticcoff, assuminggccas a default.
|
In my programfprintf()returns -1, which indicates an error. How can I find out what actual error was?
| ```
#include <errno.h>
#include <string.h>
...
rc = fprintf(...)
if (rc < 0)
printf("errno=%d, err_msg=\"%s\"\n", errno,strerror(errno))
```
|
This question already has answers here:Closed12 years ago.
Possible Duplicate:Parsing XML in Pure C
Which is the best XML Library for C?
Features I am looking out for are
1) Good Support in the form of tutorials and active mailing list.
2) Easy to develop.
3)Portabilityfor Windows, Linux, Mac.
4) I need to do parsing, validating and writing of simple XML Files.
| Libxml2should do the trick.
|
I need a method in C that the random number between decimal 65-90 [a-z] and decimal 97-122 [A-Z] returns. If I call the method the method must be a different number give back what he has previously given How can I do this in C ?
| ```
#include <stdlib.h>
char rand_az_AZ() {
char val = rand() % 52;
if (val < 26) {
val += 'a';
} else {
val -= 26;
val += 'A';
}
return val;
}
```
|
```
mov r8, FlushCounts[r14]
```
Can some one explain me what the FlushCounts[r14] is used for ? Does this mean r14 = &FlushCounts and r8 = FlushCounts ? Why is it done like this ?
| This means copy 64 bits from addressFlushCount + r14to r8. Offset inr14register is in bytes.
|
Are there any reference guides or tutorials for writing a MIPS assembler?
| If you are looking to actually write an assembler you need to know the format of the executable of the platform you are writing for (ex.ELF), then you need to use theMIPS instruction setas a reference to determine the correct machine code for your .TEXT section. Good luck!
|
I need a method in C that the random number between decimal 65-90 [a-z] and decimal 97-122 [A-Z] returns. If I call the method the method must be a different number give back what he has previously given How can I do this in C ?
| ```
#include <stdlib.h>
char rand_az_AZ() {
char val = rand() % 52;
if (val < 26) {
val += 'a';
} else {
val -= 26;
val += 'A';
}
return val;
}
```
|
```
mov r8, FlushCounts[r14]
```
Can some one explain me what the FlushCounts[r14] is used for ? Does this mean r14 = &FlushCounts and r8 = FlushCounts ? Why is it done like this ?
| This means copy 64 bits from addressFlushCount + r14to r8. Offset inr14register is in bytes.
|
Are there any reference guides or tutorials for writing a MIPS assembler?
| If you are looking to actually write an assembler you need to know the format of the executable of the platform you are writing for (ex.ELF), then you need to use theMIPS instruction setas a reference to determine the correct machine code for your .TEXT section. Good luck!
|
How do you write anNaNfloating-point literal in C?
| In C99's<math.h>
7.12 Mathematics <math.h>
```
[#5] The macro
NAN
is defined if and only if the implementation supports quiet
NaNs for the float type. It expands to a constant
expression of type float representing a quiet NaN. |
```
|
If I usegetHostByName()I only get "127.0.0.1", because it is written on /etc/host, but this is not useful to me.
However, with the following java code I actually get what I want:
```
NetworkInterface.getByName(("eth0")).getInetAddresses().nextElement().getHostAddress()
```
I think that there is a way to get the same ip address also from C?
| Check outgetifaddrs.
|
I'm trying to capture the fields in a table but I need to get that data even if the table is empty.
sqlite3_table_column_metadataisn't an option (it wasnt compiled into my version of SQLite3).
Is there is a trick to obtain that info?
| ```
PRAGMA table_info(table_name);
```
returns a list of column names
heres a link:
http://www.sqlite.org/pragma.html#pragma_table_info
|
If I usegetHostByName()I only get "127.0.0.1", because it is written on /etc/host, but this is not useful to me.
However, with the following java code I actually get what I want:
```
NetworkInterface.getByName(("eth0")).getInetAddresses().nextElement().getHostAddress()
```
I think that there is a way to get the same ip address also from C?
| Check outgetifaddrs.
|
I'm trying to capture the fields in a table but I need to get that data even if the table is empty.
sqlite3_table_column_metadataisn't an option (it wasnt compiled into my version of SQLite3).
Is there is a trick to obtain that info?
| ```
PRAGMA table_info(table_name);
```
returns a list of column names
heres a link:
http://www.sqlite.org/pragma.html#pragma_table_info
|
I want to input words from a file which are delimited by anything that isn't a letter. Is there an easy way to do this in C similar to using the \W predefined character classes in Java?
How should I approach this?
Thanks.
| Character classes in general and \W specifically really aren't related to Java at all. They're just part of regular expression support, which is available for many languages, including GNU C. SeeGNU C library Regular Expressions.
|
What does the following declaration mean?
```
unsigned char (*pArray[10][10]);
```
| Declaration
```
unsigned char (*pArray[10][10]);
```
is exactly equivalent to
```
unsigned char *pArray[10][10];
```
The parentheses are entirely redundant and have no effect at all. This is a 2D 10x10 array ofunsigned char *pointers.
|
I want to declare a new integer in the heap,
```
int *intPtr = (int*) malloc(sizeof(int));
```
How do I change the value of the space in the heap, to which*intPtrpoints to?
Thanks
| DereferenceintPtr:
```
*intPtr = 0;
```
|
Let's say I have sometypedef struct {int b;} some_t;and a pointerato such a struct. Then why is
```
(*a).b = 5;
```
not the same as
```
some_t c = *a;
c.b = 5;
```
?
| In the second,cis acopyof*a, andc.bis a copy of(*a).b.
c.b = 5modifies the copy, not the original.
|
This function aims to get the start address of the stack:
```
unsigned long find_start(void){
__asm__("movq %rsp, %eax");
}
```
When I compile it,getting an error:
```
Error: suffix or operands invalid for `movq'
```
| movqis an instruction that expects 64-bit operands.rspis a 64-bit register, whileeaxis a 32-bit register.
Perhaps tryrax?
|
What exactly is the difference between the two?
| fprintfdoes formatted output. That is, it reads and interprets a
format string that you supply and writes to the output stream the
results.
fputssimply writes the string you supply it to the indicated output
stream.
fputs()doesn't have to parse the input string to figure out that all you want to do is print a string.fprintf()allows you to format at the time of outputting.
|
I want to write regular expression library in C/C++.
What is the good starting point , any books or articles.
I know there are may libraries are available , but I want to write my own version.
| A good starting point is to use existing implementations and criticize them.
Pay attention to data structures and design decisions you don't like.Avoid them when you write your version.
|
I have a function that takes in two strings, and I want to, let's say compare the 2nd letter of each string to the other.
How do I fix this statement:
```
if (strncmp(str1 + 1, str2 + 1) != 0) {
...
```
I get an error stating that passing the argument makes a pointer from an integer without a cast.
| ```
if (str1[1] == str2[1]) {
/* Do something */
}
```
|
How do I conver an RGB component (0-255) to a floating point number in which 255 would be 1.0f and 0 would be 0.0f?
| What's wrong with dividing?
```
unsigned char red = 45;
float percentage = red/255.0f;
```
|
Why does this Compile:
```
int main()
{
{}
}
```
But this does not:
```
{}
int main()
{
}
```
| First case, you're defining a block inside a function, which is allowed (it limits visibility).
Second case, you're defining an anonymous block, which is not allowed (it needs to be predeceded by a function definition, otherwise, the compiler will never know when it will have to execute it)
|
Is there any difference betweenuintandunsigned int?
I'm looking in this site, but all questions refer to C# or C++.
I'd like an answer about the C language.
If it is relevant, note that I'm using GCC under Linux.
| uintisn't a standard type -unsigned intis.
|
For example,
```
struct node {
struct node *left, *right;
};
#define LEFT(X) (X->left)
#define RIGHT(X) (X->right)
```
I would like to forbid macro call like this without changing the existing macro interface.
```
LEFT(n) = ...
```
Any idea?
| Try this:
```
#define LEFT(X) ((X)->left+0)
#define RIGHT(X) ((X)->right+0)
```
|
Hi
How can I convert pdf to txt with qt ?
if there isn't way to do this , Is there any library for c++ that convert pdf files to txt files ?
thanks.My os is windows7 and my ide is visual studio 2008
| Foxit sells their PDF code as a library. I use it, and it's great.
http://www.foxitsoftware.com/pdf/sdk/dll/
You may know them for their very popular free Acrobat Reader alternative.
|
I am getting this exception with posix_memalign. Any idea as to why we get it?
Thanks in advance.
| Interrupted system calls are usually the result of a system call being interrupted. In other words, the process is receiving a signal while the call is executing.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.