Possible Duplicate:
Why does simple C code receive segmentation fault?
Hi,
check out the following code:
int main(int argc, char* argv[]){
char* a = "z.x.f.t.e.a";
char* b = ".";
updateStr(a,b);
return 0;
}
int updateStr(char str[], const char* delim) {
int i=0;
int wordsCounter = 0;
while ...
Possible Duplicate:
Whats your preferred pointer declaration style, and why?
Should it be:
center: int * number;
left: int* number;
right: int *number;
I see the left one as type centric the right one as variable name centric, and the center one as agnostic, but I'm really not sure. Does one make sense in certain situation...
I have a long list of constants that I need access to in several projects which are in different languages(Verilog, C, C++ and C#). Rather than repeating them in each language, is there a good way to share these?
The only thing I could think of would be a text file and a preprocessing script?
Is this the best solution or is there somet...
for example, given a matrix:
1 2 3
4 5 6
7 8 9
if you are goint to swap row[0] and row[1], resulting matrix would be:
4 5 6
1 2 3
7 8 9
can you guys help me get a code in C for this?
...
I am compiling on a 64 bit architecture with the intel C compiler. The same code built fine on a different 64 bit intel architecture.
Now when I try to build the binaries, I get a message "Skipping incompatible ../../libtime.a" or some such thing, that is indicating the libtime.a that I archived (from some object files I compiled) is no...
hello i got an unsorted linked list and i need to sort it by acertain field and afterwards i need to return the linked list to its previous unsorted condition without making a copy of the list.
...
Hi,
I have the below program to obtain current date and time.
int main(void)
{
time_t result;
result = time(NULL);
struct tm* brokentime = localtime(&result);
printf("%s", asctime(brokentime));
return(0);
}
And the output of the program is as follows :
Tue Aug 24 01:02:41 2010
How do I retrieve only the ...
I've recently established the need to store infrequently-updated configuration variables in the EEPROM of a microcontroller. Adding state to the program immediately forces one to worry about
detection of uninitialized data in EEPROM (i.e. first boot),
converting or invalidating data from old firmware versions, and
addressing of multipl...
I'm using popen to read output from shell commands. I will use fgets to read line by line.
My question is how to choose the best buffer size for my char* buffer? I remember from a professor telling us to include <limits.h> and use LINE_MAX for such things. It works fine on my Mac, but there's no LINE_MAX on Linux.
This mailing list arch...
In my parser, I have
%union {
SYMTABLE *p_entry ;
QUAD *p_quad ;
} ;
Now, SYMTABLE is the typedef for a struct. The struct and typedef are in an included file. There are no issues with this.
QUAD is the typedef for a struct (typedef struct quad QUAD). The struct and typedef are in an included file.
There is no problem doing:
b...
I am trying to write a server application that listens to both IPv6 and IPv4 connections. The proper way to accomplish this seems to be listening on IPv6 address, which will also accept IPv4 connections.
The relevant piece of code is:
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints....
I'm a web developer looking to expand my horizons in order to get better at programming as a whole. I've done a bit Java and some simple Android applications. I'm now looking into lower level languages like C and Go (which I must say has some beautiful syntax and great ideas thus far, though I'm maybe too inexperienced to comment).
So y...
How can I return an array of strings in an ANSI C program?
For example:
#include<stdio.h>
#define SIZE 10
char ** ReturnStringArray()
{
//How to do this?
}
main()
{
int i=0;
//How to do here???
char str ** = ReturnStringArray();
for(i=0 ; i<SIZE ; i++)
{
printf("%s", str[i]);
}
}
...
EDIT: An initial "float** floats;" was a typo, corrected. Also, "*floats[0] = 1.0;" does work, but "*floats[1] = 1.0;" segfauls at that point. The array is malloced. Compilation has no warnings on pedantic c99.
This worked:
(pseudo:)
void func(int*);
int i;
func(&i);
void func(int* i) {
func2(i);
}
void func2(int* i) {
*i = 2;
}
i...
If I do *ptr[x], is that equivalent to *(ptr[x]), or (*ptr)[x]?
...
Hello I was looking around on the internet and I was unable to find anything concrete. I would like to find a good Wiimote API (in C or C++) that also implements usage of the Wii Motion Plus accessory. If anyone knows of any good ones it would be greatly appreciated. Thanks.
...
I am attempting to encode video using libavcodec/libavformat. Audio works great, but when I try to encode video I get the following errors:
[libx264 @ 0x10182a000]broken ffmpeg default settings detected
[libx264 @ 0x10182a000]use an encoding preset (vpre)
easy to fix using the command line ffmpeg, but I am trying to do this in C.
...
Hi,
I am trying to declare a struct that is dependent upon another struct.
I want to use sizeof to be safe/pedantic.
typedef struct _parent
{
float calc ;
char text[255] ;
int used ;
} parent_t ;
Now I want to declare a struct child_t that has the same size as parent_t.text.
How can I do this? (Pseudo-code below.)
typedef st...
Please bear with me as i am new to marshalling. I have a C structure and function declared as the following:
typedef struct
{
char* name;
BT_ADDR address;
} DeviceList;
extern "C" _declspec(dllexport)DeviceList* PerformQuery();
The BT_ADDR structure is the same structure defined in wsbth2.h in Win CE SDK. PerformQuery return...
the MCP23017 from Microchip is an I2C based 16-pin IO extender. I have been able to set up the device once (set pin direction and values), but after that i cannot change the values as expected unless i reset / power cycle the device. this is the code i used to initalize it and set the pins up the first time:
I2C_Start();
I2C_Write(...