c

Is it possible to execute a "C" statement without a semicolon

Post an example to execute a "C" statement without semicolon( ; ) ...

Doubt regarding de-referencing structure pointers. Please explain

I am compiling this piece of code and I get compliation errors saying " dereferencing pointer to incomplete type" . I get the errors for the last print statement and before that where I try to point (*temp). num to the address of b Here's the code snippet: void main() { struct { int xx; char *y; int * nu...

How can I test the performance of a C function?

Are there some good ways to know how a function performs in C? I would like to, for example compare my own function to a library function. ...

When is stack space allocated for local variables?

I have a question about the following C code: void my_function() { int i1; int j1; // Do something... if (check_something()) { int i2; int j2; // Do something else... } // Do some more stuff... } Are there any guarantees about when stack space is allocated/deallocated for i2 and ...

Improving the quick sort.

If possible, how can I improve the following quick sort(performance wise).Any suggestions? void main() { quick(a,0,n-1); } void quick(int a[],int lower,int upper) { int loc; if(lower<upper) { loc=partition(a,lower,upper); quick(a,lower,loc-1); quick(a,loc+1,upper)...

Why the name main for function main()

Why the function name main() is retained in many languages like C, C++, Java? Why not any other names for that function? Is there any common structure for all these 3 main() (in C, C++, Java) ...

Querying MX record in C linux

Possible Duplicate: Get MX record via C program. Is there any function in C on linux by which we can query MX record (like gethostbyname).? ...

How to catch bugs of the form sizeof(#define)

I'm sure there are sometimes good reasons for taking the sizeof() a #define in C, but I occasionally come across bugs where someone has taken the sizeof() a #define instead of the sizeof() a structure (and in my codebase I don't need to take the sizeof() a #define). For example (contrived, but hopefully illustrates the point): typedef ...

Initialize a 2D-array at declarationtime in the C programming language

How do I initialize a 2D array with 0s when I declare it? double myArray[3][12] = ? ...

compiling my own kernel (not from linux-kernel source)

I'm following the kernel tutorial from here im having problems compiling my files. i get the following errors when i try to compile: main.c:8: error: expected declaration specifiers or ‘...’ before ‘size_t’ main.c:8: error: conflicting types for ‘memcpy’ ./include/system.h:5: note: previous declaration of ‘me...

Compiling program with ns_initparse() function C linux

I have installed BIND. I am using -lresolv as paramete while compiling in gcc. But it is giving error: /usr/lib/gcc/i386-redhat-linux/4.3.0/../../../crt1.o: In function `_start': (.text+0x18): undefined reference to `main' /tmp/cck9LhAK.o: In function `resolvmx': res.c:(.text+0x6b): undefined reference to `__ns_initparse' res.c:(.text+0...

linker error for ns_initparse

Here the code #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <netinet/in.h> #include <resolv.h> int main (int argc, char *argv[]) { u_char nsbuf[4096]; char dispbuf[4096]; ns_msg msg; ns_rr rr; int i, j, l; if (argc < 2) { printf ("Usage: %s <domain>[...]\n", argv[0]); exit ...

Variable arguments in C, how to get values with a generic type?

Hi guys, I'm trying to use C stdarg.h lib, with a generic type. The type int, is my generic type > to understand it, please, hold reading. So, my problem is: I have a function that accept variable number of arguments. like void function (int paramN, ...); In my program, there are no way to know, which is the type of variable arguments...

Learning C: Online resources

Can you point me to some online resources? I couldn't find any good. Also the resources shouldnt be too old. There also wasn't any SO question covering this. Or atleast I didn't find it. Edit: Practical approaches would be very nice too. Something like Real World Haskell but just for C. Is there something like this? Edit2: With "too ...

memory address positive or negative value in c?

in c, i tried to print out address of variable and address of some function. I got one is negative value, the other is positive value. My question is: why does C not represent in all negative or all positive value? Here is my code: int foo() { return 0; } int main() { int a; printf("%d\n",&a); printf("%d\n",foo); ...

Combining wide string literal with string macro

I have a macro for a character string as follows: #define APPNAME "MyApp" Now I want to construct a wide string using this macro by doing something like: const wchar_t *AppProgID = APPNAME L".Document"; However, this generates a "concatenating mismatched strings" compilation error. Is there a way to convert the APPNAME macro to a ...

Finding Max Number in an Array C Programming

I am trying to find the max number in an array. I have created a function and I am using the following code: int maxValue( int myArray [], int size) { int i, maxValue; maxValue=myArray[0]; //find the largest no for (i=0;i) { if (myArray[i]>maxValue) maxValue=myArray[i]; } return maxValue; } H...

How to find a certain number in an Array C Programming?

If I have an array and I need to display how many times the number '12' is created. I'm using a function to go about this. What resources should I look into to find how to exactly tease out this one number and display how many times it is in the array/list? Any help would be greatly appreciated. ...

C return pointer question

Hi, does this code char *a() { char *t = malloc(8); t[0] = 'a'; t[1] = 'b'; ... t[7] = 'h'; return t; } int main(void) { char *x = a(); //do something with x ..... free(x); return 0; } have any potential problems since I allocate memory in a() and use that memory in main()?? Thanks. ...

C convert from int to char

Hi, I have a simple code char t = (char)(3000); Then value of t is -72. The hex value of 3000 is 0xBB8. I couldn't understand why the value of t is -72. Thanks for your answers. ...