Hello,
I am studying pointers and I encountered this program:
#include <stdio.h>
void swap(int *,int *);
int main()
{
int a=10;
int b=20;
swap(&a,&b);
printf("the value is %d and %d",a,b);
return 0;
}
void swap(int *a,int*b)
{
int t;
t=*a;
*a=*b;
*b=t;
printf("%d and%d\n",*a,*b);
}
Can any on...
I'm learning about AI and (just for fun and practice, not profit or anything evil) I'd like to write a little bot to play a rinky-dink Flash game for me.
As a Microsoft hater, I'm embarrassed to say that I know and have used the required function calls some time ago under Windows, programming in Delphi. But these days I try to do everyt...
I am extending Python with some C++ code.
One of the functions I'm using has the following signature:
int PyArg_ParseTupleAndKeywords(PyObject *arg, PyObject *kwdict,
char *format, char **kwlist, ...);
(link: http://docs.python.org/release/1.5.2p2/ext/parseTupleAndKeywords.html)
The parameter of inter...
I have implemented tracing behavior using the -finstrument-functions option of gcc and this (simplified) code:
void __cyg_profile_func_enter(void *this_fn, void *call_site)
{
Dl_info di;
if(dladdr(this_fn, &di))
printf("entered %s\n", (di.dli_sname?di_dli_sname:"<unknown>"));
}
This works great, except for one thing: m...
Hi
I'll go straight to it. I'm working on an assignment, where I suddenly ran into trouble. I have to allocate a struct from within another function, obviously using pointers.
I've been staring at this problem for hours and tried in a million different ways to solve it.
This is some sample code (very simplified):
...
some_struct s;
pr...
I have some bison grammar:
input: /* empty */
| input command
;
command:
builtin
| external
;
builtin:
CD { printf("Changing to home directory...\n"); }
| CD WORD { printf("Changing to directory %s\n", $2); }
;
I'm wondering how I get Bison to not accept (YYACCEPT?) something as a command until...
Quick c question: How to know the length of a char* foo[]?
Thanks.
...
Hi,
which compiling a multithreaded program we use gcc like below:
gcc -lpthread -D_REENTRANT -o someprogram someprogram.c
what exactly is the flag -D_REENTRANT doing over here?
...
The idea is to use multiple arrays, each of length 2^k, to store n elements, according to binary representation of n.Each array is sorted and different arrays are not ordered in any way.
In the above mentioned data structure, SEARCH is carried out by a sequence of binary search on each array.
INSERT is carried out by a sequence of merg...
I'm working on implementing a log based file system for a file as a class project. I have a good amount of it working on my 64 bit OS X laptop, but when I try to run the code on the CS department's 32 bit linux machines, I get a seg fault.
The API we're given allows writing DISK_SECTOR_SIZE (512) bytes at a time. Our log record consists...
While there are multiple ways to reverse bit order in a byte, I'm curious as to what is the "simplest" for a developer to implement. And by reversing I mean:
1110 -> 0111
0010 -> 0100
This is similar to, but not a duplicate of this PHP question.
...
So I starting the project of writing a simplified sheel for linux in c. I am not at all proficient with c nor with Linux that's exactly the reason I decided it would be a good idea.
Starting with the parser, I have already encountered some problems.
The code should be straightforward that's why I didn't include any comments.
I am ge...
Here is my code
/*
gcc -c -Wall -g main.c
gcc -g -lm -o main main.o
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void stringToHex(const char* string, char* hex) {
int i = 0;
for(i = 0; i < strlen(string)/2; i++) {
printf("s%x", string[2*i]); //for debugging
sprintf(&hex[i], "%x", string[2*i]);
printf("h%x\n",...
Hi all,
I'm trying to draw semi-transparent rectangles on an invisible HWND. However, clearing the window with ID2D1HwndRenderTarget::Clear just makes the entire window black, so when I draw rectangles on top, they look semi-black.
If I don't Clear() and don't draw, then the window is invisible, as it should be. Clear() is the culprit ...
According to this post on Daring Fireball a new iPhone SDK Agreement release in conjunction with the iPhone OS 4.0 announcement today specifically bans any iPhone application not implemented in C, C++ Objective-C or JavaScript. The clear impact here is to the wide array of programs written in languages other than those.
Is that your rea...
How do i compile a .c file on my mac?
...
int* Register = 0x00FF0000; // Address of micro-seconds timer
while(*Register != 0);
Should I declare *Register as volatile while using armcc compiler and -O0 optimization ?
In other words: Does -O0 optimization requires qualifying that sort of variables as volatile ? (which is probably required in -O2 optimization)
...
I have the following problem: I am given a tree with N apples, for each apple I am given it's weight and height. I can pick apples up to a given height H, each time I pick an apple the height of every apple is increased with U. I have to find out the maximum weight of apples I can pick.
1 ≤ N ≤ 100000
0 < {H, U, apples' weight and ...
i have a program that receives data from a wireless device over bluetooth...i now need to do some operations in the data and then send it to the website (web server!!!) as a .csv file...i also need to authenticate the device itself from it hardware address which is also obtained in the program.i am coding this in gcc linux compiler using...
In C, what is the difference between these two?
float myF = 5.6;
printf( "%i \n", (int)myF ); // gives me "5"
printf( "%ld \n", floor(myF) ); // also "5"?
When is one preferable over the other?
...