c

How to parse a string with spaces to integer

I have a string representing an integer with spaces -- digits are grouped by three. I was considering using strchr and strcat, as in: char* remove_spaces (char* s) { char* space; while (space = strchr(s, ' ')) { *space = '\0'; strcat(s, space + 1); } return s; } But, first, I'm not sure it is safe...

Find and Replace in a C File

The Problem was to find and replace a string in a C File. I am new to C Files. I have tried the following code but I didnt get any output: #include<stdio.h> #include<string.h> int main() { FILE *f1,*f2; char *src,*dest,*s1,ch,ch1,ch2,ch3; int i; f1=fopen("input.txt","rw"); f2=fop...

OpenGL Nvidia Driver 259.12 texture not working

My OpenGL application which was working fine on ATI card stopped working when I put in an NVIDIA Quadro card. Texture simply don't work at all! I've reduced my program to a single display function which doesn't work: void glutDispCallback() { //ALLOCATE TEXTURE unsigned char * noise = new unsigned char [32 * 32 * 3]; memset(noise, 255...

scanf is not working in report

#include <stdio.h> #include <unistd.h> //#include <iostream.h> #include <sys/types.h> #include <sys/wait.h> #include <sys/types.h> int t_array[100]; int h_array[100]; int race_length=0; void cursor(int y) { int i; printf("%c[%d;%df",0x1B,y,0); } void turtle_fun() { int Ti=0; while(Ti<=race_length-1) { //...

why size is not provided in free statement

Possible Duplicate: C programming : How does free know how much to free? Hello All, How OS will come to know how much size i have to free when we define free(pointer). I mean we are not providing any size , only pointer to free statement. How's internally handle the size ? Thanks, Neel ...

C Socket Programming, 2 client queries at the same time

How can my client send two queries (in two different terminals) to the server at the same time? When i try it, only one works, the other closes socket. main () { readData (); int serverFd, clientFd, clientFd2,serverLen, clientLen; struct sockaddr_un serverAddress;/* Server address */ struct sockaddr_un clientAddress;...

Race Condition without Threads?

Let's say I have: sample.c int main (...) { char str*; get s through user input test(str); return 0; } void test (str) { copy str to new file change file permissions on new file close file } There's no possibility of a race condition here since I have no threads in my main() method. Is that true? ...

When to use Interrupt Gate or Trap Gate?

As the Intel Manual illustrated, both Interrupt Gate and Trap Gate can be used to access a handler routine. And some exceptions even share vector numbers with interrupts. I am wondering when such a shared vector is detected by the CPU, how could CPU know whether it stands for an exception or an interrupt? I am kind of confused about th...

R inline compilation of C code fails on Windows

Within the Windows XP Pro RGui, can't compile inline C code. Get error: 'sh' is not recognized as an internal or external command Clearly there is a configuration error, but can't find a way to resolve it either in R documentation or via googling. Must be a simple solution! The same R code works fine on linux: the inline C compiles ...

Receiving from message queues

I have successfully created the message queue by using the following command: msgIdHareTurtle = msgget(keyHareTurtle, 0644 | IPC_CREAT | O_NONBLOCK); Now I want to send the queue to some other process I used, msgsnd(msgIdHareTurtle, (struct msgbuf *)&bufHareTurtle, sizeof(int), IPC_NOWAIT); and I try to receive it in different...

Help with this algorithm

I have an algorithm that can find if a point is inside a polygon. int CGlEngineFunctions::PointInPoly(int npts, float *xp, float *yp, float x, float y) { int i, j, c = 0; for (i = 0, j = npts-1; i < npts; j = i++) { if ((((yp[i] <= y) && (y < yp[j])) || ((yp[j] <= y) && (y < yp[i]))) && (x...

Xcode gives 3 syntax errors dealing with Stray '\342' in program

Hello, I am working on a simple project in Objective-C in Xcode and I'm getting some stray/ errors about the following line of code: if(celsius < −273.15) { NSLog(@"It is impossible to convert temperatures less than −273.15 degrees Celsius, because this is absolute zero, the coldest possible temperature."); } It's actually...

Connecting extremely basic objective-c program to iPhone application

I was wondering if it is feasible for me to connect this simple console program I have in objective-c into a very simple iPhone application. Since I have no experience using Interface Builder, I'm not sure how long it would take for me to learn it. Also, I believe my code would have to be adjusted to some iPhone APIs, rather than using...

will Ptheard kill free dynamic memory allocated in the thread function?

Hi All, I have a thread function which allocates memory using malloc(). I kill the thread using pthread_kill without freeing the dynamically allocated memory.Will it be freed automatically once i call pthread_kill or there will be a leak? ...

How show a message over a fullscreen?

Hi guys, Well.. I want to do a thing, but I don't know how searching informations to do that. How can I send a message over the game's screen? For example: Just writing "Hello World" on a game running in fullscreen. I know C and C#, I'd like some tips how to do that. What a need to study etc. Thanks, I wait a response :) ...

How to call pointer to function defined in typedef struct

what is wrong with the following code? parseCounter1() and parseCounter1() below are two functions. I put their pointers in const OptionValueStruct so that they can be called accordingly when each element of option_values[] are gone through: typedef struct OptionValueStruct{ char counter_name[OPTION_LINE_SIZE]; int* counter_...

Why do the authors of the C/C99 standard, don't specify a ..standard for the sizeof floating point types?

I noticed on windows and linux x86, float is 4bytes, double is 8, but long double is 12 and 16 on x86 and x86_64 respectively. C99 is supposed to be breaking such barriers with the specific integral sizes. The initial technological limitation appears to be due to the x86 processor not being able to handle more than 80bit floating operat...

Strict ISO C Conformance Test

I am currently working on a C project that needs to be fairly portable among different building environments. The project targets POSIX-compliant systems on a hosted C environment. One way to achieve a good degree of portability is to code under conformance to a chosen standard, but it is difficult to determine whether a given translati...

Is there a way to force a variable to be stored in the cache in C?

Hi, I just had a phone interview where I was asked this question. I am aware of ways to store in register or heap or stack, but cache specifically? ...

How to execute an untrusted Lua file in its own environment from the C API

I want to execute an untrusted .lua file in its own environment by calling lua_setfenv() so that it cannot affect any of my code. The documentation for that function though only explains how to call a function, not how to execute a file. Currently to run the file I use: int error = luaL_loadfile(mState, path.c_str()) || lua_pcall(mSta...