c

Initializing and accessing a pointer from an array of pointers

Suppose I have the following: void **Init(int numElems) { //What is the best way to intialize 'ptrElems' to store an array of void *'s? void **ptrElems = malloc(numElems * sizeof(void *)); return ptrElems; } //What is the best way to return a pointer pointing at the index passed as a parameter? void **GetPtr(void **ptrElems, i...

how to read a string from a \n delimited file

I'm trying to read a return delimited file. full of phrases. I'm trying to put each phrase into a string. The problem is that when I try to read the file with fscanf(file,"%50s\n",string); the string only contains one word. when it bumps with a space it stops reading the string ...

how to read scanf with spaces

I'm having a weird problem i'm trying to read a string from a console with scanf() like this scanf("%[^\n]",string1); but it doesnt read anything. it just skips the entire scanf. I'm trying it in gcc compiler ...

How to define an extern, C struct returning function in C++ using MSVC?

The following source file will not compile with the MSVC compiler (v15.00.30729.01): /* stest.c */ #ifdef __cplusplus extern "C" { #endif struct Test; /* NB: This may be extern when imported by another module. */ struct Test make_Test(int x); struct Test { int x; }; struct Test make_Test(int x) { struct Test r; r.x = x; ...

Check if file exists, including on PATH

Given a filename in C, I want to determine whether this file exists and has execute permission on it. All I've got currently is: if( access( filename, X_OK) != 0 ) { But this wont search the PATH for files and will also match directories (which I don't want). Could anyone please help? Edit: As an alternative, seeing as I'm running e...

Tool to create an amalgamation/combine all source files of a library into one for C/C++?

SQLite and googletest come with a very easy-to-use, single-file version which makes it a breeze to use it in other projects, as you just need to add a single source file. Both of them use home-brew tools to create the combined source file, so I wonder if there is a more generic tool for this? It should take a list of implementation/heade...

C - Discard the edges of an arbitrary level of a multidimensional array

I have some geographical data, that I'm trying to parse into a usable format. The data is kept in NetCDF files, and is read out as a multidimensional array. My problem comes because the source of the geographical data has a strip of longitude on each side of the grid that overlaps the other side. That is, I have a longitude point of -1 d...

C signal parent process from child

I'm trying to solve a problem I've got where a child process runs execvp() and needs to let the parent know if it returns. So, after the execvp() returns (because there's been an error), how can I tell the parent that this particular event has happened so it can handle it. There's one method of writing a string of text through the pipe ...

WaitForSingleObject and WaitForMultipleObjects equivalent in linux

Hi, I am migrating an applciation from windows to linux. I am facing problem w.r.t WaitForSingleObject and WaitForMultipleObjects interfaces In my application I spawn multiple threads where all threads wait for events from parent process or periodically run for every t seconds. How can I implement this in Unix. I have checked pthread...

How to write a simple usb driver?

I make this treat because you are closing my other before i get my answer. Here is my answer clear and exactly what i want to do! I wanna create a usb driver, so my own C application be able to get into my flash drive and take information from the imported flash drive. OS: Windows Please don't close it again I still cant find my answer...

Well tested C/C++ lock free queue?

Possible Duplicate: Is there a production ready lock-free queue or hash implementation in C++ I am looking for a well-tested, publicly available C/C++ implementation of a lock free queue. I need at least multiple-producers/single-consumer functionality. Multiple-consumers is even better, if exists. I'm targetting VC's _Inter...

Do any replacements for CryptoAPI exist for Windows?

I am having major problems with cryptoAPI, and was wondering do you get any 3rd party / better solutions for windows? Main problem I have with CryptoAPI is that its not OS independent enough. I can't find the right balance in my code to get stuff to work on Windows 2003 and Windows 2008+. What I essentially want to achieve can be read...

error in finding out the lexems and no of lines of a text file in C

#include<stdio.h> #include<ctype.h> #include<string.h> int main() { int i=0,j,k,lines_count[2]={1,1},operand_count[2]={0},operator_count[2]={0},uoperator_count[2]={0},control_count[2]={0,0},cl[13]={0},variable_dec[2]={0,0},l,p[2]={0},ct,variable_used[2]={0,0},constant_count[2],s[2]={0},t[2]={0}; char a,b[100],c[100]; c...

What format specifier to use for printing "unsigned long long" in C with getting truncated values on the console?

typedef unsigned long long IMSI; IMSI imsi; when i am trying to print this using %llu as a format specifier, i am getting a rather unrelated value. What can i do to remove this problem? I am also using gcc 4.3.3 I though there might be a problem with the tracing mechanism that i have been using, but i am getting the same problem even...

C grammar in GCC source code

I'm looking for the C grammar in GCC source code, more specifically for the grammar in the yacc/bison form. ...

Translating C pointer code example to Delphi pointer syntax.

I am working with a binary file structure. The code example for reading the data is in C, and I need to read it in Delphi. I hasten to add I have no C programming experience. Given the following typedef struct { uchar ID, DataSource; ushort ChecksumOffset; uchar Spare, NDataTypes; ushort Offset [256]; } HeaderType; ... typedef stru...

"Access violation reading location" troubles retrieveing buffer from directx

The problem I am having is with the following ID3D10Texture2D *pBackBuffer; hr = mpSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*) &pBackBuffer); Below is my code... #include "DX3dApp.h" bool DX3dApp::Init(HINSTANCE hInstance, int width, int height) { mhInst = hInstance; mWidth = width; mHeight = height;...

How do you run a uncompiled CGI?

I'm going to get right to it. iPage shared hosting. Trying to use mimetex.cgi to render math. Source code is at the link. After preparing everything just as I had with a different shared host (which worked), I get errors. Tech support tells me I need to upload the uncompiled source and use that instead. ??? Rather than going with th...

Why does the output of this program change at 130?

I have the following code and it seems to me that it should always enter the true part of the if statement but, beyond 120, it appears to start executing the else clause. Why is that happening? char x; for (i=0;i<256;i+=10) { x=i; if (x==i) printf("%d true\n",i); else printf("%d false\n",i); } The output i...

How can I extract an array from an executable file?

I want to do the inverse of this question. I am embedding a file into an executable as an array, and I would later like to extract the embedded file from the executable. It seems like objcopy might be useful here but I haven't figured out the proper incantation yet. (Edit: clarify question, I somehow removed the crux of it in editing ...