c

[C] Get startup position

Hi, i need to find the startup position of a script in C. I must check if my script has been launched from /usr/bin or from another directory. I've tried with get_current_directory_name() but it returns the current path where I was browsing when i launched the script, so if I do: cd /home/myaccount/ && my-script it returns /home/myaccou...

how to printf a loop result?

How to printf results from a loop? For example if i have this something simple like this: k[0]=2; k[1]=3; k[2]=4; for (i = 0 ; i <= 2 ; i++) { x[i]=5*k[i]; } How do I print out the results for x[0],x[1],x[2] without having to keep repeating the array in printf? As in printf("%d %d %d\n",x[0],x[1],x[2]); I dont really want ...

Details on the Microsoft multi-string format.

In some of its API function Microsoft use the "multi-string" format to specify a list of strings. As I understand it, a multi-string is a null-terminated buffer of concatenated null-terminated strings. But this can also be interpreted as a list of strings, separated by a null character and terminated by two null characters. Here comes ...

GlobalAddAtom() returns 0 and GetLastError = 0x5 on Win7, works on XP

Simple code: ATOM atom = GlobalAddAtom(L"TestCpp1"); It returns 0 and GetLastError returns 0x5 (Access Denied). Nothing on MSDN about it. This is on Win7. Admin rights make no difference. Same code works on XP. AddAtom (local) works on Win7. What's causing this? ...

how to compare user given input(string) to /etc/passwd file in ubuntu in c

I want to compare user given input i.e a username to the already stored usernames in /etc/passwd file in ubuntu. I am trying it in C. any help please ...

Best way to vectorize C code by hand

Hi, I want to vectorize by hand some C code, in order to it speedup. For that purpose (SPE on the Cell processor or CBE) I want to use SIMD math. The code originally uses some physical vector calculations (speed, acceleration, etc), so in some parts of the code there is a lot of operations like; ax=a*vx+b*rx; ay=a*vy+b*ry; az=d*vz+b*rz...

BYTE BCD to ASCII conversion optimization

hello all, I've written a function in c that converts a byte (unsigned char) BCD string into ASCII. Please have look at the code and advice some improvements. Is there any other efficient way that can convert BYTE BCD to ASCII. BYTE_BCD_to_ASC(BYTE *SrcString, char *DesString) { switch (((BCD *)SrcString)->l) { ...

output of the programme

#include<stdio.h> void f(void) { int s = 0; s++; if(s == 10) return; f(); printf("%d ", s); } int main(void) { f(); } what is the output of the programme!?? i m segmentation fault ...what is it? ...

Can I set Visual Studio 2010 Professional up as an IDE for C?

Not C++, not C#, just plain old C for my computer science class. I see options for C#, F#, Visual Basic, and Visual C++, but if there's an easy way to get it to work with C, I'm not seeing it. *"set up as an IDE" in this case, meaning use Visual Studio to compile, debug, and run the written programs via VS2010, just as I've been using ...

How to Write a Scripting Language using C?

How to Write a Scripting Language using C? Any Idea? Links? ...

Lua: garbage collection + userdata

Supposing the following situation: typedef struct rgb_t {float r,g,b} rbg_t; // a function for allocating the rgb struct rgb_t* rgb(r,g,b) { rgb_t* c = malloc(sizeof(rgb_t)); c->r=r; c->g=g; c->b=b; return c; } // expose rgb creation to lua int L_rgb (lua_State* L) { rgb_t** ud = (rgb_t **) lua_newuserdata(L, sizeof(rgb_t *)); ...

C socket: does send wait for recv to end ?

Hi, I use blocking C sockets on Windows. I use them to send updates of a data from the server to the client and vice versa. I send updates at a high frequency (every 100ms). Does the send() function will wait for the recipient recv() to receive the data before ending ? I assume not if I understand well the man page: "Successful com...

Passing too many arguments to printf

Any C programmer who's been working for more than a week has encountered crashes that result from calling printf with more format specifiers than actual arguments, e.g.: printf("Gonna %s and %s, %s!", "crash", "burn"); However, are there any similar bad things that can happen when you pass too many arguments to printf? printf("Gonna ...

How does sizeof know the size of the operand array?

This may be a stupid question but how does the sizeof operator know the size of an array operand when you don't pass in the amount of elements in the array. I know it doesn't return the total elements in the array but the size in bytes, but to get that it still has to know when the array ends. Just curious as to how this works. ...

initialized data segment in C binaries running under Windows

Hi, I am for a long time trying to get a picture how is program memory handled under OS (I use Windows, but I guess this will be the same or very close on Linux). So far, I know (mostly thanks to you stackoverflow users) that local variables are stored on stack. Now I also finally understand why. So thats OK. But what I still miss is, ...

Process Memory Map (Linux Windows)

Can someone please point me to some documentation on the virtual memory maps used for Linux and Windows. By that I mean what virtual addresses, code, writable static data, the stack and the heap (along with other kernel bits) will normally be placed in, in a typical process? ...

Conditional wait with pthreads

I seem to be running in to a possible deadlock with a pthreads conditional variable. Here is the code thread function(){ for (condition){ do work /* should the thread continue? */ if (exit == 1){ break; /* exit for */ } } /* end for */ pthread_mutex_lock(&mtxExit); exit = 0; pthrea...

Which of these is faster ?

I was wondering if it was faster to render a single quad the size of the window with a texture the size of a window than to draw the bitmap directly to the window using double buffering coupled with the platform specific way of drawing to a window. ...

C preprocessor magic

I'm trying to use preprocessor tricks to declare a magic variable. Something like this: DECLARE(x) should expand to int _DECLARED_VARIABLE_x_LINE_12 if the declaration was on line 12 of the input source. I was trying to use the ## token-pasting command and the __LINE__ macro, but I either get an uninterpreted "__LINE__" in there or...

pthread_create fails w/ ENOMEM ?

I am seeing pthread_create() fail with rc=12 (ENOMEM), on a 64-bit RHEL machine with 4GB of real memory. The 'top' command shows the process is using 1G of virtual memory when thread creation fails. I am able to create 16 joinable threads, but the 17th and subsequent calls fail with the ENOMEM error (which apparently means memory -or- s...