c

use __typeof__ in input validation

Can we use __typeof__ for input validation in C program run on a Linux platform and how? If we can't then, are there any ways other than regex to achieve the same? ...

Pinning pthreads memory and cpu

I'm working on a project in C that requires threads running on separate CPUs than the initial process. I am using the pthread library to create these threads. I use sched_setaffinity to pin the main process to a cpu. Can I do the same for each thread to pin them to separate CPUs? I am also pinning the memory of the main process. Will a ...

Problem with if statement

There was an example in my book where it was asked to write a program that prints the number 1 to 100 using 5 columns (Have each number separated from the next by a tab). The solution was as following: #include "stdio.h" int main() { int i; for(i=1; i<=100; i++) { printf("%d\t", i); if((i%5)==0) printf("\n"); } return 0; } Bu...

Error: Expected primary-expression before '=='

Hello.. I'm trying to work through a book on C and I am stuck on the following error: while((c = getchar()) != EOF){ if(c >= '0' && c <= '9'){ ++ndigit[c-'0']; } else if (c == ' ' || c == '\n' || == c =='\t'){ ++nwhite; } else{ ...

call to undefined function in function main()

whenever i use a function which is called in main function, it gives this error: Call to undefined function in function main() i am using turbo c++ compiler version 4.5 and windows vista ultimate service pack 2 Can you tell which header file or something else is to be used. I am beginner in C language. An example which produces this er...

libevent2 and file io

I've been toying around with libevent2, and I've got reading files working, but it blocks. Is there any way to make file reading not block just within libevent. Or, do I need to use another IO library for files and make it pump events that I need. fd = open("/tmp/hello_world",O_RDONLY); evbuffer_read(buf,fd,4096); The O_NONBLOCK flag ...

What's wrong with this C program

Possible Duplicate: Help with C puzzle The intention of the program was to print a minus sign 20 times, but it doesn't work. #include <stdio.h> int main() { int i; int n = 20; for( i = 0; i < n; i-- ) printf("-"); return 0; } ...

Programmatically search + replace in a .doc

If I'm given a .doc file with special tags in it such as [first_name], how do I go about replacing all occurrences of it with something like "Clark"? A simple binary replacement only works if the replacement string is the exact same length. Haskell, C, and C++ answers would be best, but any compiled language would do. I'd also prefer to...

GLUTesselator for realtime tesselation?

I'm trying to make a vector drawing application using OpenGL which will allow the user to see the result in real time. The way I have it set up is with an edge flag callback so the glu tesselator only outputs triangles which I then pass to a VBO. I'v tried t make all my algorithms as fast as possible and this is not where my issue is. Ac...

gcc warning: braces around scalar initializer

Hi Guys, I have look-up-table as defined below and I'm making use of GCC. When I compile I get warnings as warning: braces around scalar initializer What does this warning mean? How should I initialize this LUT? Am I making a mistake in initializing this structures? Help!! typedef struct TECH { float velocity1, velocity2; ...

Problem regarding displaying decimal values in C Program

the data-type 'float' displays decimal numbers. by default my compiler displays up-to 6 decimals. i want to see only two decimals. for eg , when the compiler performs the operation "c=2/3" it displays "0.666666667". i want to see only "0.67" in my output screen. so what necessary changes should i make in the C program? ...

Algorithm for edge intersection?

Given Polygon P which I have its verticies in order. and I have a rectangle R with 4 verticies how could I do this: If any edge of P (line between adjacent vertexes) intersects an edge of R, then return TRUE, otherwise return FALSE. Thanks * * * * ...

How big can a malloc be in C?

I have a malloc in C that is 26901^2*sizeof(double) This got me thinking what the largest value can be here? Also, would I have any problems defining a macro to access this 2D array? #define DN(i,j) ((int)i * ny + (int)j) Because this seems to not be working for me - or I am at least unsure it is. I can't figure out how to make to...

In C, how should I read a text file and print all strings

I have a text file named test.txt I want to write a C program that can read this file and print the content to the console (assume the file contains only ASCII text). I don't know how to get the size of my string variable. Like this: char str[999]; FILE * file; file = fopen( "test.txt" , "r"); if (file) { while (fscanf(file, "%s",...

difference between exit and return

What is difference between return and exit statement in C Programming ...

Determine input from different devices

My PC has two devices working like keyboard, the normal keyboard and a HID (Human Interface Device) input device (it's a remote control). I want separate the input from keyboard and from remote, capturing only the remote control. How can I write a program in C/C++ to do this task? It's not a easy task because this program is operating ...

I'm learning C, and have made up a Tic Tac Toe table. Now, how can I reference the individual cells?

I'm learning C, so decided to try and make a Tic Tac Toe game, using ASCII art as the table. I don't have much yet... #include <stdio.h> #define WIDTH 2; #define HEIGHT 2; int main (int argc, char *argv[]) { printf("Welcome to Tic Tac Toe!\n\n"); int width = WIDTH; int height = HEIGHT; // Make grid for (int...

C file checksum

how can i make a checksum of a file using C? i dont want to use any third party, just default c language and also speed is very important (its less the 50mb files but anyway) thanks ...

How to find the ASCII Characters?

How to write a program to print the ASCII characters of the input given by user? ...

cudaMemcpy fails to copy values

I am calling cudaMemcpy and the copy returns successfully however the source values are not being copied to the destination. I wrote a similar piece using memcpy() and that works fine. What am I missing here? // host externs extern unsigned char landmask[DIMX * DIMY]; // use device constant memory for landmask unsigned char *tempmask; ...