c

Is there a function in c that will return the index of a char in a char array?

Is there a function in c that will return the index of a char in a char array? For example something like: char values[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; char find = 'E'; int index = findInedexOf( values, find ); ...

Code organization style for C?

I know some higher level languages, all web based (PHP, javascript, some python). I've finally decided to learn a lower level language, and I've decided to go with C. The problem is that all the languages I use are based heavily on OOP. Seeing as (based on the research I did) C doesn't have classes or inheritance. As a result, I ask y...

How to Check for Certain Characters in C

I am writing a script where I need to make sure they only put in certain characters. These include "x", "/", "+", "-", "%" (basic math operators), every letter from a -z and every number. I have the following below that only checks for alpha and number. How can I check that only certain one are used, and everything else, such as "&" or "...

Call C++ class member function from C (Visual Studio)

I need to call a C++ member function from a C program. I created .cpp/.h wrapper files in the C code, wrapping the C++ member functions. i.e.- wrapper.cpp #include "wrapper.h" extern "C" { void wrap_member1() { Class::member1(); } void wrap_member2() { Class::member2(); } } and wrapper.h: #include <windows.h>...

How do I get the stack pointer in a Valgrind tool in a portable way?

I'm writing a Valgrind tool and in the instrumented code I need to pass the guest's stack pointer to a dirty function. What I'm currently doing to get the stack pointer is this: IRTemp temp = newIRTemp (sbOut->tyenv, gWordTy); addStmtToIRSB (sbOut, IRStmt_WrTmp (temp, IRExpr_Get (offsetof (Ve...

TCP Operation Timed Out

I've got a TCP server and client written in C that opens up a connection that should be open forever. On the first send, errno returns 0 which is fine. On subsequent sends it gives me an errno 60 which is that the operation timed out. The packet is still recieved by the server though and nothing seems to be wrong. What could cause the th...

Which javascript interpreter is the easiest to embedd in a C application?

There are a few available and i want to support many platforms so i guess V8 isn't that good unless someone has written an interpreter patch for it. ...

what is the following code trying to demonstrate?

int main(void) { char x; int y=1280; x=y; printf("%d", x); } OUTPUT: 0 I remember that int = 4 byte and char is merely 1 byte. So we're trying to squeeze a 4 byte data into a 1 byte space, but why is the output 0?? ...

Activation Record in C

void test(int p1[10], int p2) { int l1; int l2[10]; printf("params are at %d and %d\n", &p1, &p2); printf("locals are at %d and %d\n", &l1, &l2[0]); } int main(void) { test(5, 10); } I'm a bit confused by the code above... how can we supply an argument of 5 to the test function when the function has already speci...

Where Does SYMBOL TABLE Reside?

Hi, I wanted to know where does SYMBOL TABLE reside. Is it in .obj files or an .exe file? Thanks in advance. ...

What is the exact definition of a Metacircular Interpreter?

Is it legal to call a C compiler written in C or a PHP interpreter written in PHP metacircular? Is this definition valid only for languages of a specific type, like Lisp? In short, what are the conditions that an interpreter should satisfy for being called Metacircular? ...

On a 32bit machine, every memory location is capable of holding 1 byte of data?

for example int = x; because int is 4 bytes they would take up 4 memory locations x x x x ...

Array Size and Addresses in C

When I compiled the following code, it shows that y and the beginning of the array are 60 units apart. But according to my calculation, it should have been 4 * 10 (for the array) + 4 (for k) + 4 (for y) = 48. Also array[12] = 17 was assigned to element 12, since there's no element 12, the implementation should have gone to y and overwri...

Unassigned variable has a value....

The follow code generates y is the answer, but i've never assigned 42 to y, how could y be 42? #include <stdio.h> void doit2(void) { int x; int y; if (x == 42) { printf("x is the answer\n"); } else if (y == 42) { printf("y is the answer\n"); } else { printf("there is no a...

Help with array parameters in C

In the following code, when the line doit(x,y) is executed, what is passed to the pointer? The addresses of x and y or the values of x and y? #include <stdio.h> int doit(int x[], int y[]) { x = y; x[0] = 5; y[2] = 10; } int main(void) { int x[2]; int y[2]; x[0] = 1; x[1] = 2; y[0] = 3; y[1] = 4; doit(x,...

passing input from standard input to a file (C programming)

I wrote a program in C which has a function that processes files which can be passed to it by a file pointer. void process_my_file(FILE *fptr, ...) { /* do work */ } I would like to read some input from standard input and pass it to my function, without having to write the input to a temporary file. Would it be possible to pass it ...

how do we print a number that's greater than 2^32-1 with int and float? (is it even possible?)

how do we print a number that's greater than 2^32-1 with int and float? (is it even possible?) ...

Converting a number from a given base to base 10.

I am trying to convert from any base to base 10. For an input of 010111 base 2 it gives me 1, and for 35 base 9 it gives me 18 which should be 38. Any suggestions? #include<stdio.h> #include<math.h> #include<string.h> #define LENGTH 6 double pow( double x, double power ); int main() { char input[LENGTH+1] ; int base; unsi...

how to tokenize string to array of int in c?

Anyone got anything about reading a sequential number from text file per line and parsing it to an array in C? What I have in a file: 12 3 45 6 7 8 3 5 6 7 7 0 -1 4 5 What I want in my program: array1[] = {12, 3, 45, 6, 7, 8}; array2[] = {3, 5, 6, 7}; array3[] = {7, 0, -1, 4, 5}; I've been through several ways to read it, but the ...

Array of char* should end at '\0' or "\0" ?

Lets say we have an array of char pointers char* array[] = { "abc", "def" }; Now what should be put in the end ? char* array[] = { "abc", "def", '\0' }; or char* array[] = { "abc", "def", "\0" }; Though, both works. We only have to put the condition to check the end accordingly like array[ index ] != '\0'; or array[ index ]...