c

Why am i able to access other variables using array indexing?

Here len is at A[10] and i is at A[11]. Is there a way to catch these errors?? I tried compiling with gcc -Wall -W but no warnings are displayed. int main() { int A[10]; int i, len; len = sizeof(A) / sizeof(0[A]); printf("Len = %d\n",len); for(i = 0; i < len; ++i){ A[i] = i*19%7; } A[i] = 5; A[i + 1] = 6; printf("L...

Pointer best practice

I am just starting to learn C and (of course) struggling with pointers :) Given this snippet: int *storage, *storage_p; storage = malloc(sizeof(int[GROW_BY])); storage_p = storage; // do something with storage, using storage_p free(storage); storage = NULL; Is it really necessary to have two variables declared to work with the malloc...

accessing the last 2 bytes of an integer

i have a struct that contains an integer and a char..how do i access the last 2 bytes of my int?? ...

Width as a variable when using fscanf [C++]

I am trying to read in a certain portion of a file and that amount of data is different per line but I know how how many bytes of info I want. Like this: 5bytes.byte1byte2byte3byte4byte5CKSum //where # of bytes varies for each line (and there is no period only there for readability) Actual data: 05AABBCCDDEE11 03AABBCC22 04AABB...

Bringing another app's window to front on Mac in C

How do I bring another app's window to front on Mac in C/C++? I have the app's pid. I found solutions for AppleScript, but I'm not familiar with AppleScript. (and also not with Objective C) Thanks! edit: I cannot use Carbon in this program, because it must be a 64 bit binary. edit2: I'm also interested in Carbon and Cocoa solutions. I c...

Warning: C4013 in C lang

#include <stdio.h> #include <string.h> void prints(char *menu) { int p = 0; p = navigation(p, menu); } int navigation(int p, char *menu) { return p; } void main(void) { char *menu[] = {"data", "coming", "here"}; prints(*menu); printf("\n"); } How can i fix this the warning is: Warning 1 warning C4013: 'navigation' ...

Is C inefficient compared to Assembly?

Possible Duplicate: When is assembler faster than C? Hello, This is purely a theory question, so, given an "infinite" time to make a trivial program, and an advanced knowledge of C and Assembly, is it really better to do something in Assembly? is "performance" lost when compiling C into Assembly (to machine code)? By perfor...

Can I force the C pre processor to generate a new line ?

Possible Duplicate: How can I make the preprocessor insert linebreaks into the macro expansion result? #define IDENTIFIER { /*new line here*/\ my_multiline(); /*new line here*/\ macro(); /*new line here*/\ } /*new line here*/ Can I force the C pre processor to generate a new line in it's expan...

Problem with calling a function?!

If I have those functions: void main(void) { char *menu[] = {"data", "coming", "here"}; prints(**************); // here printf("\n"); } void prints(char **menu) { int a; while(*menu) { printf("%s", **menu); menu ++; } a = 0; } How to call prints function ??? ...

Debugger is getting weird!?

#include<stdio.h> #include<string.h> int main(void) { int f; char duma[] = "asd char"; f = strlen(duma); } So when I run it in debugger and in "watch" table type strlen(data) its getting back a message like word like strlen() does not exist or something like that, the mean is that strlen does not exist, however in locals f =...

Key differences between Ruby and C

What are the key differences between Ruby and C? ...

C/C++ need a clever way to track function calls

I am looking for a clever way to track function calls and returns. I know I can use the debugger, but I would like a way to just have it print something out to the terminal when calling a function vs having to step through code. I am thinking that I might be able to use the preprocessor, but I am not sure what would be the best way to go...

What is the C version of RMI

I have a set of functions in C/C++ that I need to be available to accept calls and return values to C/C++ code in a remote location, similar to RMI on the java platform. With RMI the Java methods are set up through the rmiregistry and remain available in memory to accept requests. I'm looking for similar functionality in C/C++, but i'm a...

Evenly distributed dashed lines with OpenGL?

I notice that drawing dashed lines with GL will not make them even apart unless each vertex is equidistant from the last. Is there a way to simply make the whole path dashed evenly regardless of the distance between each point? Thanks ...

QPen equivalent class in objective c.

I need to draw some figure on context(Canvas). So , need a class which is equivalent to QPen. If anyone know plz help me out. ...

dyld: lazy symbol binding failed: Symbol not found - nm reports symbol found

Fairly abstract question here, as I don't know quite where to start my own investigations. I have a C package constructed with CMake that produces librpdb.so; I have a Ruby Gem set up for the same library, which produces rpdb.bundle. When used in Ruby, I get this: dyld: lazy symbol binding failed: Symbol not found: _RPDB_RuntimeStor...

What happens when there is a request for memory block which is not a power of 2?

Suppose we do a malloc request for memory block of size n where 2 ^k !=n for k>0. Malloc returns us space for that requestted memory block but how is the remainig buffer handled from the page. I read Pages are generally blocks of memory which are powers of two. Wiki states the following: Like any method of memory allocation, the heap...

C Program: Line not drawing

#include<conio.h> #include<stdio.h> #include<graphics.h> #include<math.h> #include<dos.h> //#include"device.h" #define round(a) ((int)(a+0.5)) void main() { float x1,y1,x2,y2,dx,dy,x,y; int l,k,xinc,yinc; // int gmode,gdrive=DETECT; //initgraph(&gdrive,&gmode,"c\\tc\\bgi"); clrscr(); printf("enter the co-ordinates"); prin...

typedef,#define

Can anybody explain the difference between #define int* char and typedef int* char; ...

How many times could I run this program

I have a machine with 128M memory, and this is the program. while(1) { ptr = malloc(1024 * 1024 * 100); if (NULL == ptr) { printf("malloc 100M Failed\n"); return 1; } n+=100; printf("malloc %dM\n", n); } I found from output that malloc run 20 times, why? ...