c

Produce tones at certain time-interval using C programming

Im using C language for a PIC18F to produce tones such that each of them plays at certain time-interval. I used PWM to produce a tone. But I don't know how to create the intervals. Here is my attempt. #pragma code // void main (void) { int i=0; // set internal oscillator to 1MHz //OSCCON = 0b10110110; ...

What is the best way to evenly scale one byte?

In C I need to scale a uint8_t from 0 - 255 to 0 - 31 What is the best way to do this evenly? ...

What is double star?

So, I saw this: error:(NSError **)error in the apple doc's. Why two stars? What is the significance? ...

Does C allocate memory automatically for me?

I have been writing C for only a scant few weeks and have not taken the time to worry myself too much about malloc(). Recently, though, a program of mine returned a string of happy faces instead of the true/false values I had expected to it. If I create a struct like this: typedef struct Cell { struct Cell* subcells; } and then lat...

Is modifying a string pointed to by a pointer valid?

Here's a simple example of a program that concatenates two strings. #include <stdio.h> void strcat(char *s, char *t); void strcat(char *s, char *t) { while (*s++ != '\0'); s--; while ((*s++ = *t++) != '\0'); } int main() { char *s = "hello"; strcat(s, " world"); while (*s != '\0') { putchar(*s++); ...

Read file access/modification timestamp

What win32 API C functions can I use to read the modification/access/created dates of a file? ...

Coding a website in C?

I was just reading the http://www.meebo.com/ About Us page, and read this line : "plus, we're one of the few still around using C!" Considering that meebo is an online chat client, how do they work with C? How can they use C for the backend? How does it interact with the frontend? For example, let's say a user creates a new account, and...

fseek / rewind in a loop

I have a situation in a code where there is a huge function that parses records line-by-line, validates and writes to another file. In case there are errors in the file, it calls another function that rejects the record and writes the reject reason. Due to a memory leak in the program, it crashes with SIGSEGV. One solution to kind of ...

Do I cast the result of malloc?

In this question, someone suggested in a comment that I should not cast the results of malloc. I.e. int *sieve = malloc(sizeof(int)*length); rather than int *sieve = (int *)malloc(sizeof(int)*length); Why would this be the case? ...

How to check if a unicode character is within given range in C?

The following function was written for java and has been adapted for C. bool isFullwidthKatakana(WideChar C) { return(('\u30a0'<=C)&&(C<='\u30ff')); } The problem is that my framework ("CodeGear C++Builder") shows this error: [BCC32 Warning] Unit1.cpp(101): W8114 Character represented by universal-character-name '\u30a0' ...

How to convert char * to BSTR?

Hi, How can I pass a char * from C dll to VB Here is sample code: void Cfunc(char *buffer,int len) { BSTR buf_bstr = SysAllocString((BSTR)buffer); VBptr.VBfunc(buf_bstr,len); } This function is not working, In actual some other values are sent to the VB rather than the actual value. Can Anyone .. tell me how the solution for ...

How do I access an individual character from an array of strings in c?

Just trying to understand how to address a single character in an array of strings. Also, this of course will allow me to understand pointers to pointers subscripting in general. If I have char **a and I want to reach the 3rd character of the 2nd string, does this work: **((a+1)+2)? Seems like it should... ...

C Arrays and unbroken lists

/edit: thanks for the help so far, however I haven't got any of the solutions to take the sample input and give the sample output. My description isn't the clearest, sorry. I have an array composed of binary data. What I want to do is determine how long each unbroken segment of 1s or 0s is. Say I have this data: 0111010001110 In an ...

How do I read/write a shared variable with pthreads?

I have two threads, using C pthreads on linux. One of them writes data and the other is reading it. I'm using a variable to allow the read thread when is allowed to read and the write one when is allowed. So the mutex applies to this boolean variable called "newData". My question is: do I need to lock/unlock the mutex around the accesses...

Calling a obj-c method with a parameter

I've change a c-style function to an objective-c method. As a method, how do i use it? NSString* myfunc( int x ) is now: - (NSString *)myFuncWithParam:(int)x c code: myString = myfunc(x); // works obj-c code: myString = myFuncWithParam(x); // fails to compile. From one of the answers: myString = [object myF...

Obj-C methods: calling with parameters

I've been using c-style functions, but I just learned they can't see instance variables. So I was advised to convert them to methods. NSString* myfunc ( int x ) becomes: - (NSString *)myfunc:(int)x and myString = myfunc(x); becomes myString = [myString myfunc: x]; ?? This compiles with ominou...

C++ - Circular array with lower/upper bounds ?

I want to create something similar to a double linked list (but with arrays) that works with lower/upper bounds. A typical circular array would probably look like: next = (current + 1) % count; previous = (current - 1) % count; But what's the mathematical arithmetic to incorporate lower/upper bounds properly into this ? 0 (lower b...

What does this error mean: "error: expected specifier-qualifier-list before 'type_name'"?

I'm a bit new to working with c/c++, so sorry if this is a dumb question. I've been working on the Cell processor and I'm trying to create a struct that will hold an spe_context_ptr_t, which will be used within the thread to launch an spe context and will also hold a pointer to something else that will be passed to the spu context from w...

Wine linker error: trying to create .lnk

I'm trying to create an .lnk file programatically. I would prefer to use C, but C++ is fine (and is what all the MSDN stuff is in). The relevant code sample is: #include <windows.h> #include <shobjidl.h> #include <shlguid.h> HRESULT CreateLink(LPCSTR lpszPathObj, LPCSTR lpszPathLink, LPCSTR lpszDesc) { HRESULT hres; IShellLink* p...

Initializing an array of pointers to pointers

This example works fine: static char *daytab[] = { "hello", "world" }; This doesn't: static char *daytab[] = { {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} }; The way I see it is that the first example creates an array that is filled with pointers to the tw...