c

run a command line argument prog

how to run command line arguments program of c in turbo c ...

What happens if I re-alloc and the new size is 0. Is this equivalent with a free ?

Given the following code: int *a = NULL; a = calloc(1, sizeof(*a)); printf("%d\n", a); a = realloc(a, 0); printf("%d\n", a); return (0); It returns: 4078904 0 Is this realloc equivalent to a free ? NOTE: I am using MinGW under WindowsXP. ...

Pointers in C# to make int array?

The following C++ program compiles and runs as expected: #include <stdio.h> int main(int argc, char* argv[]) { int* test = new int[10]; for (int i = 0; i < 10; i++) test[i] = i * 10; printf("%d \n", test[5]); // 50 printf("%d \n", 5[test]); // 50 return getchar(); } The closest C# simple example I c...

question about fgets

Is this safe to do? (does fgets terminate the buffer with null) or should I be setting the 20th byte to null after the call to fgets before i call clean. // strip new lines void clean(char *data) { while (*data) { if (*data == '\n' || *data == '\r') *data = '\0'; data++; } } // for this, assume that the file...

What does \x mean in c/c++?

char arr[]= "\xeb\x2a"; BTW,are these the same: "\xeb\x2a" vs '\xeb\x2a' ...

can I read exactly one UDP packet off a socket?

Using UNIX socket APIs on Linux, is there any way to guarantee that I read one UDP packet, and only one UDP packet? I'm currently reading packets off a non-blocking socket using recvmsg, with a buffer size a little larger than the MTU of our internal network. This should ensure that I can always receive the full UDP packet, but I'm not s...

hiding exectables using ADS (Alternate data streams)

i hear that NTFS alternate data streams can be used to hide running executabes. eg supporse i have an exe called hiddenProgram.exe on windows xp,using cmd.exe or system(char*) calls in c, type hiddenProgram.exe > c:\windows\system32\svchost.exe:hiddenProgram.exe start c:\windows\system32\svchost.exe:hiddenProgram.exe starts svchost a...

Is size_t only in C++ standard or C standard as well?

Is size_t only in C++ standard or C standard as well? I cannot find a C header in the "/usr/include" tree that defines size_t. If it is not in the C std, is GCC just doing some magic to make things work? Thanks, Chenz ...

Flush kernel's TCP buffer for `MSG_MORE`-flagged packets

send()'s man page reveals the MSG_MORE flag which is asserted to act like TCP_CORK. I have a wrapper function around send(): int SocketConnection_Write(SocketConnection *this, void *buf, int len) { errno = 0; int sent = send(this->fd, buf, len, MSG_NOSIGNAL); if (errno == EPIPE || errno == ENOTCONN) { throw(exc, &S...

How to compile x64 code with Visual Studio in command line?

I want to compile a simple hello-world-style program using the Windows command line. cl file_name.c is easy enough. Now I want to do the same thing in 64 Bit. What should I do? ...

VERY simple C program won't compile with VC 64

Here is a very simple C program: #include <stdio.h> int main (int argc, char *argv[]) { printf("sizeof(short) = %d\n",(int)sizeof(short)); printf("sizeof(int) = %d\n",(int)sizeof(int)); printf("sizeof(long) = %d\n",(int)sizeof(long)); printf("sizeof(long long) = %d\n",(int)sizeof(long long)); printf("sizeof(float) ...

Get an input from keyboard without 'return' in C

How do i get an input from keyboard, without pressing 'return' in C / Mac Os ...

Compiling without libc

I want to compile my C-code without the (g)libc. How can I deactivate it and which functions depend on it? I tried -nostdlib but it doesn't help: The code is compilable and runs, but I can still find the name of the libc in the hexdump of my executable. ...

Double indirection and structures passed into a function

I am curious why this code works: typedef struct test_struct { int id; } test_struct; void test_func(test_struct ** my_struct) { test_struct my_test_struct; my_test_struct.id=267; *my_struct = &my_test_struct; } int main () { test_struct * main_struct; test_func(&main_struct); printf("%d\n",main_struct->id); } This works, but...

How to patch source files

I am trying to patch dmenu with the files provided here: http://aur.archlinux.org/packages.php?ID=27334 I do not know how to do it, I've read that I should do patch file-to-patch the-patch, but in the patch provided there is more than one file involved. I've tried patching manually but I failed, it will not compile. ...

What is the difference between AF_INET and PF_INET constants?

Looking at examples about socket programming, we can see that some people use AF_INET while others use PF_INET. In addition, sometimes both of them are used at the same example. The question is: Is there any difference between them? Which one should we use? If you can answer that, another question would be... Why there are these two sim...

Using getchar() in a while loop

#include <stdio.h> main() { int c ; while ((c = getchar()) != EOF) { int isEOF = (c==EOF); printf("is %c EOF: %d ", c, isEOF); } } Why printf() method is called twice on every input char here? If i give a input 'a', I am getting the result like E:\C_workouts>gcc CharIO.c -o CharIO.exe E:\C_workouts>C...

how to get AutoIncrement value after JetUpdate() in Extensible Storage Engine (JetBlue)

after calling JetSetColumns() and then JetUpdate() how do I retrieve the values for any freshly assigned autoincrement values? ...

Good Package for Fitting Polynomial Trend Lines

Given a simple data set, I would like to be able to calculate a trending formula given it's a second order polynomial regression. In fact, it would be great if one could even forecast X periods during calculation (similar to what Excel does). I'm looking for a portable C/C++ package that's relatively easy to use, and allows it to spit ...

Why is Read-Modify-Write necessary for registers on embedded systems?

I was reading http://embeddedgurus.com/embedded-bridge/2010/03/different-bit-types-in-different-registers/, which said: With read/write bits, firmware sets and clears bits when needed. It typically first reads the register, modifies the desired bit, then writes the modified value back out and I have run into that consrtuct while m...