c

Clearing Contents of a File in C++ knowing only the FILE *

Is it possible to clear the contents (ie. set EOF to the beginning/reset the file) in C++ knowing just the FILE*? I'm writing to a temp file with wb+ access and wish to sometimes clear it and truncate it without adding the calls to fclose and fopen. I dont think it's possible... but if not, why not? Thanks in advance! ...

Writing a POSIX-compliant kernel

I've wanted to write a kernel for some time now. I already have a sufficient knowledge of C and I've dabbled in x86 Assembler. You see, I've wanted to write a kernel that is POSIX-compliant in C so that *NIX applications can be potentially ported to my OS, but I haven't found many resources on standard POSIX kernel functions. I have foun...

C Pointer Write Error

void fileNameProcess(char * inputName){ int size =strlen(inputName); bool change=false; char * name=inputName; for(int i =0; i<size; i++){ char temp=* (name+i); if(temp<0x10||temp>0x5b){ change=true; }else if(0x19...

Segmentation Fault with strcat

Hi, I'm having a bit of a problem with strcat and segmentation faults. The error is as follows: Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000000 0x00007fff82049f1f in __strcat_chk () (gdb) where #0 0x00007fff82049f1f in __strcat_chk () #1 0x0000000100000adf i...

Pointer syntax in C: why does * only apply to the first variable?

The following declaration in C: int* a, b; will declare a as type int* and b as type int. I'm well aware of this trap, but what I want to know is why it works this way. Why doesn't it also declare b as int*, as most people would intuitively expect? In other words, why does * apply to the variable name, rather than the type? Sure you ...

__typeof -identifier not found

For some reason I keep getting error C3861: '__typeof': identifier not found when I compile my program! I'm including the following libraries: <iostream> <stdlib> <stdio> Any ideas? thanks Edit: More example User.h class User{} main.cpp void f(User* p) { . . . __typeof(p) ... . . . . } ...

Why am I getting an ferror on my source file using zlib deflate?

EDIT // open output file for writing if ( ( outfilefd = fopen( file_name, "w+t" ) ) == NULL ) { fprintf(stderr, "Unable to create file\n"); exit(1); } Write to the file, then need to zip it. Opening a .z file and then calling def() FILE *zipFile; if ( ( zipFile = fopen( "C:\\LOGS\\test.txt.z", "w+t" ) ...

problem with casting float -> double in C when fread

I have a problem with casting from float to double when fread; fread(doublePointer,sizeofFloat,500,f); if i change double pointer to float pointer, it works just fine. However,i need it to be double pointer for laster on, and i thought when i write from small data type (float)to bigger data type(double)'s memory, it should be fine. ...

what is the equivalent to passing by address in c#

void Afunction(int* outvar) { if(outvar) *outvar = 1337; } note the qualities: it allows you to optionally pass a variable by reference, so that it can be set by the function. my closest guess would be (ref int? outvar) but that produces ref (int?) NOT (ref int)? which is what I need this functionality is hardly a scarc...

How would I use gstreamer to stitch a set of images together to form a video slideshow.

I'd like to take a set of images and a sound track and use that to form a basic video slideshow using gstreamer. There seems to be a lot of documentation and examples of basic gstreamer usage like playing a video or audio file, or even transcoding and the like. But I can't seem to find anything particularly useful for, I suppose, video ...

ipad, Need help with a memory leak

I have this code: void getStringWithTag(char* pFile, long sizeSound, char* tag, char* ret, float* currentPos){ char* tagCopy; tagCopy = (char*)malloc(256 * sizeof(char)); int totalLen = 0; int tempLen = 0; memset(tagCopy, 0, 256); memset(ret, 0, 128); pFile += ((int)*currentPos); while (totalLen+(*currentPos) < sizeSound) { if (*pFi...

How to compile third party c library in Xcode ?

Hi, i tried to do a sip client for iphone. I tried to use oSip or eXosip2 , i download their package ,and compile it using "./configure""make""make install " I get some *.a library, and i include there headers. When i compile it , their is warning , this *.a library formate doesn't support ! It's really annoying, what should i do to ...

Append item to a file before last line in c

The footer should update with current time and hour when a new Item added to the file. Here is the sample file format, ITEM1 ITEM2 06/07/2010 10:20:22 //footer line The “item” has to append in the existing file, prior to the footer line, and the footer should be updated with new value. I am having to variables, “item” and “time” which ...

Adding Conditionals & Functions to a Math Parser

I have a binary tree based mathematical expression parser I built, which works great for 'normal' math, like: (3.5 * 2) ^ 1 / (1 << 6). however, I would like to expand it a little to add a ternary selection operator, mirroring the one from C: {expr} ? {true-expr} : {false-expr}. I would also like to add functions, like sin(x) or ave(...)...

Multithreaded data structure : concurrent stack

Hi all, I'm looking for a C implementation of a concurrent stack (like Cilk THE protocol) that would allow the main thread to push and pop (the pop operation would be at the begining of the stack for example) and a distant thread to pop (this pop operation would be at the end of the stack) with every precaution that has to be taken. If...

Is typedef just a string replacement in code or somethings else?

I was curious to know how exactly typedef works. typedef struct example identifier; identifier x; In above statement is 'identifier' just replaced (somethings like string replacement) with 'struct example' in code? If no, what does typedef do here? please enlighten! ...

Can I use a variable to specify the size of a struct member array?

I am trying to represent a HD page in a struct. The code below does not work, because page_size is not a constant. int page_size = 4096; struct page { char data[page_size]; /* some methods */ } Since I am building and randomly accessing arrays of pages, it would be nice if I could treat a page as a fixed length struct of size p...

What is the benefit of the const keyword in programming?

Possible Duplicate: Sell me on using const correctness I'm eager to know the answer. [to "What is the benefit of const keyword in programming?"] ...

C inline assembly on linux, write string from stack to stdout

how can i write a string (eg. "Hello") to stdout from the stack? without, data-segments, that is. void main() { __asm__( "movl $0x4, %eax \n\t" "movl $0x1, %ebx \n\t" // put "Hello" on the stack and load its address into %ecx "movl $0x5, %edx \n\t" ...

Is there a profiler for C (gcc) to profile code lines separately?

Hi there, I come from a Matlab background so I am used to a profiler which profiles every single line and not just every function like gprof or callgrind. Is there a profiler for C with a similar feature? Thanks! ...