I would like to port a few applications that I use on Linux to Windows. In particular I have been working on wdiff. A program that compares the differences word by word of two files.
Currently I have been able to successfully compile the program on windows through Cygwin. However, I would like to run the program natively on Windows simi...
I've been reading through the Linux kernel (specifically, 2.6.11).
I came across the following definition:
#define unlikely(x) __builtin_expect(!!(x), 0)
(from linux-2.6.11/include/linux/compiler.h:61 lxr link)
What does !! accomplish? Why not just use (x)?
See also:
How does logical negation work in C?
Double Negat...
My matrix multiplication code is
int matMul(int ld, double** matrix)
{
//local variables initialize
omp_set_num_threads(nthreads);
\#pragma omp parallel private(tid,diag,ld) shared(i,j,k,matrix)
{
/* Obtain and print thread id */
tid = omp_get_thread_num();
for ( k=0; k<ld; k++) {
if (matrix[k][k] == 0....
I am currently trying to build a very basic serial shell with my arduino.
I am able to get an output from the device using Serial.read() and can get the character it has outputted, but I cannot work out how to then add that character to a longer to form the full command.
I tried the logical thing but it doesn't work:
char Command[];
...
Hi,
I have some content like this:
author = "Marjan Mernik and Viljem Zumer",
title = "Implementation of multiple attribute grammar inheritance in the tool LISA",
year = 1999
author = "Manfred Broy and Martin Wirsing",
title = "Generalized
Heterogeneous Algebras and
Partial Interpretation...
Hi,
I have some input like this:
" aaaaa bbb \n cccccc\n ddddd \neeee "
And I need to sanitize it like this:
"aaaaa bbb cccccc ddddd neeee"
Basically:
Trim all blank spaces at the beginning and end of the string
Strip all new lines
Strip all spaces when there is more than one, but always leave ONE space between words
I...
limits.h specifies limits for non-floating point math types, e.g. INT_MIN and INT_MAX. These values are the most negative and most positive values that you can represent using an int.
In float.h, there are definitions for FLT_MIN and FLT_MAX. If you do the following:
NSLog(@"%f %f", FLT_MIN, FLT_MAX);
You get the following output:
F...
Hello,
This is my first time doing this sort of project so apologies if the question is silly.
I've got a question about using a C project with a project in the iPhone SDK. I've dragged and dropped the C project into the iPhone project in Xcode (so it appears in the screenshot below).
sjeng.h is a file inside GameEngine.xcodeproj, but...
so the following converts big endians to little ones
uint32_t ntoh32(uint32_t v)
{
return (v << 24)
| ((v & 0x0000ff00) << 8)
| ((v & 0x00ff0000) >> 8)
| (v >> 24);
}
works. like a charm.
I read 4 bytes from a big endian file into char v[4] and pass it into the above function as
ntoh32 (* reinterpret_cas...
In the following bit of code, pointer values and pointer addresses differ as expected.
But array values and addresses don't!
How can this be?
Output
my_array = 0022FF00
&my_array = 0022FF00
pointer_to_array = 0022FF00
&pointer_to_array = 0022FEFC
...
#include <stdio.h>
int main()
{
char my_array[100] = "some cool string";
pri...
Is there any difference between a variable declared as static outside any function between C and C++. I read that static means file scope and the variables will not be accessible outside the file. I also read that in C, global variables are static . So does that mean that global variables in C can not be accessed in another file?
...
Hi, when I'm trying to compile my c program it gives me this error warning: integer constant is too large for 'long' type
which refers to these lines
int barcode, a, b, c;
scanf("%d", &barcode);
a = barcode / 1000000000000;
b = barcode / 100000000000 % 10;
c = barcode / 10000000000 % 10;
and the rest is fine. I know I'm not supposed ...
Hello, I am trying to use my own function to get the file size from a file. I'll use this to allocate memory for a data structure to hold the information on the file.
The file size function looks like this:
long fileSize(FILE *fp){
long start;
fflush(fp);
rewind(fp);
start = ftell(fp);
return (fseek(fp, 0L, SEEK_END...
related to http://stackoverflow.com/questions/2520535/gcc-multi-dim-array-or-double-pointer-for-warning-free-compile , is there a way to return so-called "decayed array pointer" from a function? in summary (suppose 2 dim array) returning int (*a)[5] format rather than int** format?
as far as I see, when returned int** pointer is sent to...
Hi,
I got the following code:
char buffer[2047];
int charsRead;
do {
if(fscanf(file, "%2047[^\n]%n%*c", buffer, &charsRead) == 1) {
// Do something
}
} while (charsRead == 2047);
I wanted to convert this code to use dynamically allocated variables so that when calling this code often I won't get heavy memory leakage....
Hi again, here is my coding which gives me the error 'warning: unknown conversion type character 0x20 in format'
int subtotal;
long long a,b,c,d,e,f,g,h,i,j,k,l,m;
subtotal = (1*(a+c+e+g+i+k))+(3*(b+d+f+h+j+l));
printf(" = %d % 10 = %d; (10 - %d) % 10 = %lld\n", subtotal,subtotal%10,subtotal%10,m);
any idea why this is wrong?
...
strtok wont work correctly when using char *str as the first parameter (not the delimiters string).
Does it have something to do with the area that allocates strings in that notation? (which as far as i know, is a read-only area).
thanks in advance
example:
//char* str ="- This, a sample string."; // <---doesn't work
char str[] ="-...
Update: OK I see it's a bubble sort, but is it less efficient because it doesn't stop when there's no swap on a particular run? It runs until first is null.
Hi, I have a sorting algorithm as follows. My question is, which sorting algorithm is this? I thought it was bubble sort, but it does not do multiple runs. Any idea?
Thanks!
//sort...
Hi,
ist is possible? What would be the easiest way? I tried to compare in the input string character to character so
if(char([i]=="^M") char[i]=""
but it does not work.
By the way, if I were able to check it, what is the wistes substitution? to "" ?
Thanks
...
In my C OpenGL app the window style requires WS_SYSMENU to show the close and minimize buttons, but it also brings up a stupid menu everytime I press alt.
How can I disable this?
...