c

Permutation for numbers in C

Hi programming masses, I'm trying to write a C function to list all permutations of a set of numbers, in groups of five, including repeat numbers: 15-11-49-43-5 2-30-34-6-11 So it's easy enough to write a function to grab all permutations of a number set and throw them out, but mapped to a certain group size, i'm somewhat stuck.. T...

Simple question on file seeking in C.

Say I write in a file Mesh: 1 Vertices: 345 Indices: 123 V: 1,3,4 1,4,5 .. Mesh: 2 Vertices: 456 Indices: 42 etc. How do I go about seeking at any position? E.g. I want to go to Vertices: of Mesh 2 or V: of Mesh 3 etc. What's the proper way to go about these things? ...

Does this number have more than D decimal places?

Let's say I want to write a function that does the following: Given a number N, when N is rounded to D1 digits does the result include more than D2 decimal places, not counting trailing zeroes? For example, say N is .01001, D1 is 4, and D2 is 2. The question becomes, does .0100 include more than 2 decimal places, not counting t...

C - #define question

When you see a line like: #define IX(i,j) ((i)+(N+2)*(j)) is that equivalent to: int IX(int i, int j) { return ((i)+(N+2)*(j)); } How do you know the return type etc? ...

Is there a difference between int* and Type*?

I am implementing a queue in C. I have a struct like: struct Node { Node* next; Node* previous; // data } Because next and previous are just pointers, does it make a difference if I use Node* or int*? eg: struct Node { int* next; int* previous; // data } ...

C: Sending long strings with send()

I'm using Linux and trying to send a long message through send(). The message is 1270 bytes, but my client application is only receiving 1024 bytes. Since 1024 bytes is such a convenient number, I'm guessing that send() can only send 1024 bytes at a time. I looked at the man page for send, but all it says about long messages is: Wh...

Undeclared identifiers in C

Hi all I've been trying to compile a program that uses PCL. However, I keep getting this error: test.c:23: error: ‘PCL_CNT_TYPE’ undeclared (first use in this function) test.c:23: error: (Each undeclared identifier is reported only once test.c:23: error: for each function it appears in.) test.c:23: error: expected ‘;’ before ‘i_result_...

malloc fails catastrophically

I am trying to implement a Queue in C. Coming from Java and other managed languages, I am really struggling with memory management. Here is the enqueue() function: int enqueue(Queue q, int value) { Node newNode = malloc(sizeof(Node)); /*newNode->value = value; if (q->size == 0) q->head = newNode; else q...

C 2D array Memory allocation

Greetings all, Is there any issue in the following logic for allocating 2D array: unsigned char ** Malloc2D_uchr(int ht, int wt, unsigned char initv) { int h, w; unsigned char **x; x = (unsigned char **) malloc(sizeof(void *) * ht); DEBUG_PRINT_MEMLOC_EXIT(x,"malloc failed (%s,%i)\n",sizeof(void *)*ht); x[0] = (uns...

C Programming weird struct setup

I am trying to build this project and for some reason the program hangs when I run it. It works fine if i comment out the data cache lines. but it cannot make a call to makeCache for two different caches i dont know why any C experts know. Im new to c. /* * main.c * * Created on: Sep 16, 2010 * Author: TJ */ #include <std...

Is unsigned char a[4][5]; a[1][7]; undefined behavior?

One of the examples of undefined behavior from the C standard reads (J.2): — An array subscript is out of range, even if an object is apparently accessible with the given subscript (as in the lvalue expression a[1][7] given the declaration int a[4][5]) (6.5.6) If the declaration is changed from int a[4][5] to unsigned char a[4]...

Casting one struct pointer to other - C

Please consider the following code. enum type {CONS, ATOM, FUNC, LAMBDA}; typedef struct{ enum type type; } object; typedef struct { enum type type; object *car; object *cdr; } cons_object; object *cons (object *first, object *second) { cons_object *ptr = (cons_object *) malloc (sizeof (cons_object)); ptr->type = CONS; ...

When do I need the Windows SDK and what is .NET for?

I am a student and after taking some introductory programming courses in Java, C, and just finishing up a book on C++, I would like to start developing applications for Windows. I have done my best to page through google and find the answers I need, but I seem to be at a loss. When would I need the Windows SDK over just the regular API...

Learning C coming from managed OO languages

I am fairly comfortable coding in languages like Java and C#, but I need to use C for a project (because of low level OS API calls) and I am having some difficulty dealing with pointers and memory management (as seen here) Right now I am basically typing up code and feeding it to the compiler to see if it works. That just doesn't feel ...

Simple printf with sizeof does not work at all.

I got the most simple code to display sizeof() of a datatype, say an int. #include <stdio.h> int main() { printf('%i', sizeof(int)); } No matter what I do, such as put sizeof(int) into an integer, or use 'zu' instead of 'i', it hands me this error: error: invalid conversion from ‘int’ to ‘const char*’ Is there something wrong wi...

What's the cause of my segmentation fault?

I'm trying to write a program that reads in entries from a file into a dynamically allocated array of structures using input redirection. My program compiles fine but I'm getting a segmentation fault and I'm having trouble finding the cause. Here's my Program: #include <stdio.h> #include <stdlib.h> #include <string.h> typedef str...

What is this piece of objective-c doing?

I'm not really sure what this is doing. Is dateFormatter only settable the first time? static NSDateFormatter *dateFormatter = nil; if (dateFormatter == nil) { dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setTimeStyle:NSDateFormatterMediumStyle]; [dateFormatter setDateStyle:NSDateFormatterMediumStyle]; } ...

how does do{} while(0) work in macro?

Though this topic has been discussed many times in this forum and all other forums, still I have doubts. Please help. How does the do{} while(0) in macro work in Linux kernel? For example, #define preempt_disable() do { } while (0) How does it disable preempt? #define might_resched() do { } while (0) How does it reschedule?...

compiling c , c# code under windows for arm9 (AT91SAM9RL64)

Hi fellas, i read much tutorials for cross-compiling c code for arm chips. When i try it with codesourcery lite´s: gcc-none-eabi under windows (no cygwin) arm-none-eabi-gcc -c -nostartfiles -nostdlib -o main main.c arm-none-eabi-ld -Ttext=0x8000 -o main.elf main arm-none-eabi-objcopy -O binary main.elf main.bin won´t start on the bo...

Naming conventions in UNIX C functions (_t and _st)

I notice that there are some function return types named *****_t or ******_st. What do "_st" and "_t" mean? ...