c

Assigning a value to a variable gets stored in the wrong spot?

Hello, I'm relatively new to C, and this is baffling me right now. It's part of a much larger program, but I've written this little program to depict the problem I'm having. #include <stdio.h> int main() { signed int tcodes[3][1]; tcodes[0][0] = 0; tcodes[0][1] = 1000; tcodes[1][0] = 1000; tcodes[1][1] = 0; ...

How fast can you make linear search?

I'm looking to optimize this linear search: static int linear (const int *arr, int n, int key) { int i = 0; while (i < n) { if (arr [i] >= key) break; ++i; } return i; } The array is sorted and the function is supposed to return the index of the fi...

C, Linux: Receiving data from multiple multicast address on same port - how to distinguish them?

2 vote down star I have an application that is receiving data from multiple multicast sources on the same port. I am able to receive the data. However, I am trying to account for statistics of each group (i.e. msgs received, bytes received) and all the data is getting mixed up. Does anyone know how to solved this problem? If I try to ...

Indentation control while developing a small python like language

Hello, I'm developing a small python like language using flex, byacc (for lexical and parsing) and C++, but i have a few questions regarding scope control. just as python it uses white spaces (or tabs) for indentation, not only that but i want to implement index breaking like for instance if you type "break 2" inside a while loop that'...

How to get all n sets of three consecutives elements in an array or arraylist with a for statement ?

Hi, I'm trying to do a convex hull approach and the little problem is that I need to get all sets of three consecutive vertices, like this: private void isConvexHull(Ponto[] points) { Arrays.sort(points); for (int i = 0; i <points.length; i++) { isClockWise(points[i],points[i+1],points[i+2]); } ...

To create a large file consisting of strings and numbers in c or c++

Hi All, I need to create a larger file, which would be filled by strings and numbers of a certain length. Eg File content would be like : Dougan | 15 | Sapient Patric | 25 | Patni. IGHIGH | 10 | IHIUDWHKJDBHKJ I need an outline as to how I can approach this in either c or c++.. Kindly let me know if more information is needed. ...

Split string "A10" into char 'A' and int 10

Given a string consisting of a single character followed by a number (one or two digits), I would like to split it into a character and an integer. What is the easiest way to accomplish this? My thoughts so far: I can easily grab the character like so: string mystring = "A10"; char mychar = mystring[0]; The hard part seems to be gra...

replacing elements horizontally and vertically in a 2D array

the code below ask for the user's input for the 2D array size and prints out something like this: (say an 18x6 grid) .................. .................. .................. .................. .................. .................. code starts here: #include <stdio.h> #define MAX 10 int main() { char grid[MAX][MAX]; int i,j,...

program to print odd numbers and even numbers on seperate threads

Hi, I am learning programming using pthreads. How can I write a program to print odd numbers and even numbers on separate threads. ...

Creating multiple process and simulation in C via fork()

i want to create multiple process groups which will call different functions. i write the code below. firstly i want to get following output ./fork 4 5 I am a child: 1 PID: 22330 I am a child2: 1 PID: 22334 I am a child: 2 PID: 22331 I am a child2: 5 PID: 22338 I am a child: 4 PID: 22333 I am a child: 3 PID: 22332 I am a child2...

execl doesn't work in a while(1) loop, server side; C script

I have a problem with a little C script which should run as a server and launch a popup for every message arriving. The execl syntax is correct because if I try a little script with main() { execl(...); } it works. When I put it in a while(1) loop it doesn't work. Everything else is working, like printf or string operation, but not ...

BLAS and CUBLAS

I'm wondering about Nvidia's CUBLAS Library. Does anybody have experience with it? For example if I write a C program using BLAS will I be able to replace the calls to BLAS with calls to CUBLAS? Or even better implement a mechanism which let's the user choose at runtime? What about if I use the BLAS Library provided by Boost with C++? ...

How to read empty string in c

I have a problem with reading empty string in c.I want to read string from the following - 1.ass 2.ball 3.(empty) 4.cat but when i use gets() it does not treat (empty) as string[2].it read 'cat' as string[2].So how can i solve this problem.Which thing should i use?? plz someone help. char str1[15002][12]; char str2[15002][12]; char...

I need to know inside of "while(fscanf != EOF){blah}" if the next fscanf is going to return EOF-- because I need to keep executing portions of the {blah} code after fscanf hits EOF. ?

I've got some code executing in a while(fscanf != EOF) loop. However, even when fscanf has finished executing, I need to keep running that code until some conditions are met. I mean I guess I could copy/paste the code to outside the while(fscanf) loop, and only use global variables, but that seems messy. Surely someone has encountered so...

FILE* issue PPU side code

We are working on a homework on CELL programming for college and their feedback response to our questions is kinda slow, thought i can get some faster answers here. I have a PPU side code which tries to open a file passed down through char* argv[], however this doesn't work it cannot make the assignment of the pointer, i get a NULL. No...

This is a valid C code but not a valid C++ code?

In some library I'm using (written in C) its StorePGM(image, width, height, filename) char *image; int width, height; char *filename; { // something something } All functions are defined this way. I never seen such function definitions in my life. They seem to be valid to MSVC but when I compile it as C++ it gives errors. What is ...

When is a>a true ?

Right, I think I really am living a dream. I have the following piece of code which I compile and run on an AIX machine: AIX 3 5 PowerPC_POWER5 processor type IBM XL C/C++ for AIX, V10.1 Version: 10.01.0000.0003 #include <stdio.h> #include <math.h> #define RADIAN(x) ((x) * acos(0.0) / 90.0) double nearest_distance(double radius,doub...

Strange errors in Visual C++ :: 'malloc' : function does not take 1 arguments

Error 38 error C2660: 'malloc' : function does not take 1 arguments C:\VolumeRenderer\render.cpp 296 1 VolumeRenderer Error 39 error C2660: 'malloc' : function does not take 1 arguments C:\VolumeRenderer\render.cpp 412 1 VolumeRenderer Error 40 error C2660: 'malloc' : function does not take 1 arguments C:\VolumeRenderer\render.cpp 414 1 ...

useless class storage specifier in empty declaration

Hello, gcc 4.4.1 c89 I have the following code and I get a warning: useless class storage specifier in empty declaration static enum states { ACTIVE, RUNNING, STOPPED, IDLE }; However, if i remove the static keyword I don't get that warning. I am compiling with the following flags: -Wall -Wextra Many thanks for...

How to ignore the sign of a variable in C ?

I am using C as the programming language. How to ignore the sign when using float/signed int variables? For example if float/signed int f = -40 or +40 The result should be same after a mathematical operation like a+b*f ...