c

Possible to trap write to address (x86 - linux)

I want to be able to detect when a write to memory address occurs -- for example by setting a callback attached to an interrupt. Does anyone know how? I'd like to be able to do this at runtime (possibly gdb has this feature, but my particular application causes gdb to crash). ...

Header Files in C and C++

Should every .C or .cpp file should have a header (.h) file for it? Suppose there are following C files : Main.C Func1.C Func2.C Func3.C where main() is in Main.C file. Should there be four header files Main.h Func1.h Func2.h Func3.h Or there should be only one header file for all .C files? What is a better approach? ...

Ignoring ctrl-c

I'm trying to write a shell and I'm at the point where I want to ignore ctrl-c. I currently have my program ignoring SIGINT and printing a new line when the signal comes, but how can I prevent the ^C from being printed? When pressing ctrl-c, here is what I get: myshell>^C myshell>^C myshell>^C but I want: myshell> myshell> myshell>...

What is an XML parser? Using Expat

This might seem like a simple question. But I have been looking for an XML parser to use in one of my applications that is running on Linux. I am using Expat and have parsed my XML file by reading one in. However, the output is the same as the input. This is my file I am reading in: <?xml version="1.0" encoding="utf-8"?> <books> ...

passing char buffer to functions and getting the size of the buffer

Hello, I have set the buffer to size 100. I display the buffer in the main function where the buffer is declared. However, when I pass the buffer to the function and get the sizeof '4', I was thinking it should be 100, as that is the size of the buffer that I created in main. output: buffer size: 100 sizeof(buffer): 4 #inc...

Geting xml data using xml parser expat

Hello, I have managed to parse ok. But now I am having trouble getting the values that I need. I can get the element and the attributes. But cannot get the values. I would like to get the value of frame in this xml it is 20. /* track the current level in the xml tree */ static int depth = 0; /* first when start element is encountered *...

C Errors (Beginner)

#include <stdio.h> main(void) { file *file = fopen("words.txt","r") if(file != null) { char line[128]; while(fgets( line, sizeof line, file) != null) { fputs ( line, stdout ); } fclose ( file ); } } This is my code. im trying to read a file, and output the content. but this gives me error codes main.c:...

Circular file logging

Hi All, I would like to know if there are any logger libraries for C , that can do circular file logging? I am currently looking at log4C, But cant find enough docs on it that can say it will do circular logging. if anyone has done this. kindly let me know. Thanks ...

How to import a function from a DLL made in Delphi?

Can you tell me how do i use the following functions in my C program. Delphi DLL - Exported functions : function GetCPUID (CpuCore: byte): ShortString; stdcall; function GetPartitionID(Partition : PChar): ShortString; stdcall; I don't have the source code for that DLL so I must adapt my C program to that DLL and not the other way aro...

Best practices for building and packaging on AIX.

Does anyone know where i can find some best practices guide for building and packaging C applications on AIX. I m using the xlc compiler and make. Thanks ...

comparing using strcmp

Hello, compiling with gcc C99 I am trying to compare 2 string using string compare. However, I seem to be getting a stack dump on the strcmp line. **attribute will contain these, so I am looking for frametype. [name] [time] [type] [time] [name] [callref] [type] [string] [name] [port] [type] [int16] [name] [frametype] [type] [int16] ...

C strcpy() - evil?

Some people seem to think that C's strcpy() function is bad or evil. While I admit that it's usually better to use strncpy() in order to avoid buffer overflows, the following (an implementation of the strdup() function for those not lucky enough to have it) safely uses strcpy() and should never overflow: char *strdup(const char *s1) { ...

Problem with IP_HDRINCL?

I already asked this question on raw IP packet implementation. But I didn't get any solutions. My code: if((s = WSASocket(AF_INET, SOCK_RAW, IPPROTO_TCP, 0, 0, 0))==SOCKET_ERROR) // Socket { printf("Creation of raw socket failed."); return 0; } if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, (char *)&optval, sizeof(optval))...

Customizable implementation of sprintf()

Can anyone point me to a source code file or to a package that has a good, reusable implementation of sprintf() in C which I can customize as per my own need? An explanation on why I need it: Strings are not null terminated in my code (binary compatible). Therefore sprintf("%s") is useless unless I fix the code to understand how to rend...

Easiest way to flip a boolean value?

I just want to flip a boolean based on what it already is. If it's true - make it false. If it's false - make it true. Here is my code excerpt: switch(wParam) { case VK_F11: if (flipVal == true) { flipVal = false; } else { flipVal = true; } break; case VK_F12: if (otherVal == true) { otherValVal = false; } els...

Why would you use 'extern "C++"'?

In this article the keyword extern can be followed by "C" or "C++". Why would you use 'extern "C++"'? Is it practical? ...

long long alignment problem (MSVC vs. GCC)

I'm writing C cross-platform library but eventually I've got error in my unittests, but only on Windows machines. I've tracked the problem and found it's related to alignment of structures (I'm using arrays of structures to hold data for multiple similar objects). The problem is: memset(sizeof(struct)) and setting structures members one ...

pthread callbacks interupt user input

I have written my own stop_watch module. That will create a thread and go to sleep for a period of seconds. Once the seconds have expired it will call a callback function in the main.c and inform the user the time has expired. This is so that the user will only have 3 seconds to enter a digit and they will have to enter 5 digits. If th...

How can I get a list of files in a directory using C or C++?

How can I determine the list of files in a directory from inside my C or C++ code? I'm not allowed to execute the 'ls' command and parse the results from within my program. ...

C# Interop with C vs Interop with Java: Which is better/easier/faster?

I have an application in C# that currently authenticates to LDAP. We want to extend functionality to support IBM's Tivoli Access Manager, which is comprised of a Policy Server, and an LDAP server (and other modules as well). Unfortunately authenticating with the LDAP server for our customer is not acceptable, thus we must bind with the p...