c

how can a process execute network code

Hello guys, I am a beginner to networking and I have a few questions regarding networking. 1)How can a process execute code that is sent from a different computer on the network. Generally a process's code segment cannot be changed once its loaded to ensure protection. (Also I can execute some arbitrary code to corrupt the process's mem...

Allocating sufficient memory for unknown length tokens

For various reasons I won't discuss here, I am writing a simple tokenizer in C. Below is an example I hacked out which resizes the token buffer in predetermined increments as necessary when reading characters from the input stream. It will ultimately reach the size of the largest token which can obviously accommodate smaller tokens. Is t...

Software interrupt

Hi, How can I program software interrupt in C? I know need to write an interrupt servicing routine and then interrupt the CPU so that the routine can be called, but I don't know how to do that in C. Also, I don't know how to register that routine with Interrupt descriptor table. I have an x86-64 CPU (AMD Turion64 X2) and I am using gcc c...

Make a string null in a single line

To make a string a null string i wrote this: #include<stdio.h> #include<conio.h> #include<string.h> int main() { char str[15]="fahad uddin"; strlen(str); puts(str); for(int i=0;str[i]!='\0';i++) strcpy(&str[i],"\0") ; puts(str); getch(); return 0; } Before this i tried: #include<stdio.h> #include<c...

How to debug to assembly level with visual studio express?

I'm curious about how some features are implemented under the hood,like : pEvent->WaitForCompletion(INFINITE, &evCode); I tried to step into it but failed. Is there a way to do that? ...

How to understand .def files?

LIBRARY Vcam.ax EXPORTS DllMain PRIVATE DllGetClassObject PRIVATE DllCanUnloadNow PRIVATE DllRegisterServer PRIVATE DllUnregisterServer PRIVATE The above is from Filters.def, what does it actually do? ...

How to have gtk control+c to be handled, or not?

I'm using pygtk, and would like to handle control+c sometimes to do a special copy action, but other times to let gtk handle it. For example, I'd like to put an object on my clipboard if it is available, or just let control+c be used in the normal fashion in a text entry. Currently I have an ActionGroup associated with "c" but that alwa...

Using unit testing framework for C Check

I am trying to use unit testing framework for C called Check. I installed the package as instructed on the file INSTALL in the package: ./configure make make check -> run self-tests that come with the package (pass successfully). make install After doing that I failed to run my own test so finally I decided to use the package exampl...

copy a string in c - memory question:

Hi all, consider the following code: t[7] = "Hellow\0"; s[3] = "Dad"; //now copy t to s using the following strcpy function: void strcpy(char *s, char *t) { int i = 0; while ((s[i] = t[i]) != '\0') i++; } the above code is taken from "The C programming Language book". my question is - we are copying 7 bytes to what ...

Any fundamental difference between source and header files in C?

I don't quite understand how things should be separated in C's source and header files. I often see many projects with two sets of files with the same name (sans the extension denoting source and header files). So far, from this lack of understanding, when I've written libraries, I've chucked all the class and class method code into one...

Is it possible to list mutexs which a thread holds

Firstly, I use pthread library to write multithreading c program. Threads always hung by their waited mutexs. When I use the strace utility to find a thread is in FUTEX_WAIT status, I want to know which thread hold that mutex at the time. But I don't know how could I make it. Are there any utilities could do that? Someone told me java v...

i'm running gdb with attach on a process how do i halt the continuing i'm stuck there

hi i'm pretty much using gdb for the first time, i tried looking at the internet for info about my prob but i could not find. i run $gdb then i'm running attach <mypid> then i see that my process is stuck (which is probably ok) now i want it to continue running so i run continue and my process continues running but from here i...

structure with linked-list memory dump

Hi, is there any standard approach which I've missed at school to dump C structure with nested linked lists on disk in reasonable way? What I don't want to do is: use protocol-buffers or any other like serializators, don't want to create JSON, XML or other I've few ideas: allocate accurate memory amount (or extend existing one) and...

i cant call my multidimensional array function from my main function. what is wrong with my parameters? declarations? variables? etc.

#include<stdio.h> #include<string.h> #define MAX_VAL 100 //Function declaration int input_values(int Z[][k], int j, int k); int main(void) { int A(int [ ][k], int, int); int m, n; char comm[100]; while(1){ printf("\n>>"); gets(comm); if(strcmp(comm,"MAKE A")== 0) input_values(A, j, k ); } } //make or overwri...

Freeing memory allocated for a Tree - C

I have a tree defined like, struct tree { char label[MAX_LENGTH]; char value[MAX_LENGTH]; struct tree *child; struct tree *next; }; Now I need to free the memory allocated by this tree. I wrote the following code. unsigned int tree_free(struct tree *root) { struct tree *current = NULL, *next = NULL, *child = NULL;...

libxml2 HTML chunk parsing

I'm downloading HTML from a website. The file can be quite large so while the file's downloading, I want to already parse the available chunks of HTML so that the process appears faster for the end-user of my program. I don't have control over how the cunks are generated, so a chunk can begin in the middle of a word, e.g. like so: chunk...

Writing a library that needs to be object-orientated. Objective-C or C++ for the highest compatibility with C?

I am planning to write an open-source library which really needs to be written in an object-orientated language. One problem is that the library should be possible to use with C, where it doesn't matter of direct inclusion of source code or (dynamic) linking to a precompiled library. I know all three C++, C and Objective-C. Objective...

Similar syntax but one shows error but another does not

Hiii all I made this program today int main() { int a = 1,2; /* Shows error */ int b = (1,2); /* No error */ } Why first one shows error while second one does not? Just ( ) makes one program compile. Why? --Shruti ...

For loop condition to stop at 0 when using unsigned integers?

I have a loop that has to go from N to 0 (inclusively). My i variable is of type size_t which is usually unsigned. I am currently using the following code: for (size_t i = N; i != (size_t) -1; --i) { ... } Is that correct? Is there a better way to handle the condition? Thanks, Vincent. ...

How to build-in gprof support to a program built with SCons?

Greetings, Here is my SConstruct file: env = Environment() env.Append(CCFLAGS=['-g','-pg']) env.Program(target='program1', source= ['program1.c']) Also here is the output of the compilation: scons: Reading SConscript files ... scons: done reading SConscript files. scons: Building targets ... gcc -o program1.o -c -g -pg program1.c g...