Here's a very basic C snippet to open and read a file:
int fd = open("test.txt",O_RDONLY);
char buf[128];
int reader = read(fd,buf,128);
int i;
for (i=0;i<strlen(buf);i++)
{
printf("%i: I read: %c", i, (int)buf[i]);
}
I'm also including these standard headers:
#include <stdio.h>
#include <stdlib.h>
#include <...
Hi!
Is it posible to define a structure with a pointer to that type of structure? What I mean is:
typedef struct {
char* name;
node* parent;
} node;
As far as I tried or read, I don't know how to do this or if it's even possible.
...
I've added a feature to my app that allows the user to save a business's contact details to the address book; however, to guard against adding multiple entries I want to check that the entry doesn't already exist.
Any idea how to do this? The iPhone developer documentation seems a little unclear. I'm using the C api to add the contact.
...
I'm building a class wrapper for the mysql c api, specifically at the moment for mysql_real_escape_string and I don't think I'm doing it quite right.
this is what I have for the function:
std::string Database::EscapeString(const char *pStr)
{
char *tStr = new char[strlen(pStr)*2+1];
mysql_real_escape_string(m_sqlCon, tStr, pStr...
I have a pointer to my char array like this.
unsigned char *recvBuf;
recvBuf = (unsigned char *)malloc(sizeof(char)*RECVBUF);
I then pass that to a function defined as
void setHeader(MyHeader *myHeader, unsigned char *buffer)
Which copies the first 12 bytes into a struct
Then I try and pass it to another function later on ...
typedef struct unit_class_struct {
char *name;
} person;
person * setName() {
person * array;
array = malloc (2 * sizeof(person));
array->name = strdup("Robert");
array++;
array->name = strdup("Jose");
return array;
}
int main()
{
person *array;
arra...
I've always been curious about audio conversion software, but I have never seen a proper explanation from a beginners point of view as to how to write a simple program that converts for example, a mp3 file to a wav. I'm not asking about any of the complex algorithms involved, just a small example using a simple library. Searching on SO, ...
I know in C you can declare a string and the number of characters like below,
char mystring[50];
with '50' being the number of characters.
However, what is proper procedure if the user is going to be inputting the contents of the string (via scanf("%s", mystring);)? Do I leave it as,
char mystring[0];
leaving it as '0' since I ha...
Looking to write an SNMP and Netflow tool for Linux\BSD and seeking advice on language selection, C or Java.
The tool will collect Netflows, send and recieve SNMP queries, connect to a Postgresql Databases and will be fronted by a web interface (PHP), in the future it will interface with devices using web services.
Normally I would hav...
Text books say that & (addressof) operator doesn't apply to cannot be applied to expressions,
constants, or register variables.
Does constants mean only literals like 'A', '7' etc or variables declared with const keyword as well?
I think this mean only literals since following code compiles:-
int main()
{
const int i=10;
const int *ip;
...
I am trying to pass a structure array pointer and a pointer to a structure array pointer into a function and then have it modified rather than using a return.
This example code is indeed pointless, its just a learning example for me.
Basically I want to create array[0]...array[1]..array[2] and so on and have a pointer that points to t...
If I have a function that returns a (char) in c and I have a (char* getSomething) how do I cast it? It is giving me an error when I try to cast it through either (char*) or (char*)&
Example:
If the function is :
char* getSomething;
getSomething = getSth(var);
getSth return a char
...
I am looking for an efficient (optionally standard, elegant and easy to implement) solution to multiply relatively large numbers,and store the result into one or several integers :
Let say I have two 64 bits integers declared like this :
uint64_t a = xxx, b = yyy;
When I do a*b, how can I detect if the operation result in an overflow...
I've been experimenting with emacs tempo mode and it seems likely to save me lots of typing (always a good thing), but I haven't gotten it to work exactly the way I want it. On the wiki, there is an example for elisp similar to what I want to do which works as expected. Here is the complete .emacs that I tested it on:
(require 'tempo)...
The following code compiles on a C++ compiler.
#include<cstdio>
int main()
{
struct xx
{
int x;
struct yy
{
char s;
struct xx *p;
};
struct yy *q;
};
Would there be any difference in behavior while compiling with a C compiler?
i.e. would there be any compiler error?
...
I want to compile / install the IP2Location Python extension found here:
www.ip2location.com/python.aspx
I tried following the instructions at these sites:
eli.thegreenplace.net/2008/06/28/compiling-python-extensions-with-distutils-and-mingw/
boodebr.org/main/python/build-windows-extensions
But I am getting no where. The pr...
I know this question has probably been asked in this forum many times and in the web as well. I am asked to create an implementation of a big integer in c++, however there is a constraint that one of my constructor should take an int as an argument... so I am guessing there will be more than one non-default constructor... so my question ...
How do I replicate the following Python code with the Python C API?
class Sequence():
def __init__(self, max):
self.max = max
def data(self):
i = 0
while i < self.max:
yield i
i += 1
So far, I have this:
#include <Python/Python.h>
#include <Python/structmember.h>
/* Define a ne...
Is it possible to have a (fixed) array which stores its elements in the read-only segment of the executable and not on the stack? I came up with this code but unfortunately it is very unflexible when it comes to adding, moving or deleting items. How do I verify that the strings are indeed stored in the read-only segment? I tried readelf ...
in the following c code:
char name[20];
int a;
int b;
for(i=0;i<10;i++)
{
printf("\nEnter name, a & b: ");
scanf("%s %d %d",name,&a,&b);
}
does scanf read in the '\n', entered at the end of scanf() in 1st iteration, for the 2nd iteration inputs?
...