Suppose I have a static variable declared inside a function in c.
If I call that function multiple times, does the static variable get re-allocated in memory every time the function call? If it does, why the last value can always be maintained?
Example:
void add()
{
static int x = 1;
x++;
printf("%d\n",x);
}
int main()
{
...
Right now i am doing an assignment but find it very hard to parse the user input in C. Here is kind of input user will input.
INSERT Alice, 25 Norway Drive, Fitzerald, GA, 40204, 6000.60
Here INSERT is the command (to enter in link list)
Alice is a name
25 Norway Drive is an address
Fitzerald is a city
GA is a state
40204 is a zip cod...
In C, I can do like this:
char s[]="hello"; or char *s ="hello";
so i wonder what is the difference? I want to know what actually happen in memory allocation during compile time and run time.
...
I have following thing which i wanted to convert to int.
char *ptr; // this can point to variable length of string
int balance = functionToConverIntoint(ptr)
So is there any such function in C "functionToConverIntoint" which can do this job?
...
My application creates a helper pthread that I need to have run at a higher priority than the main thread.
I tried to set the priority of the created thread like this:
struct sched_param param;
pthread_attr_t tattr;
pthread_attr_init(&tattr);
pthread_attr_getschedparam(&tattr, ¶m);
param.sched_priority = sched_get_priority_max(SCHE...
I heard that in c, if I do:
char *s = "hello world".
The "hello world" is actually stored in read-only memory.
I am not so clear about read-only memory. Can anybody explain? Is that like a flag to compiler that tells compiler that do not write into that section?
...
Is there an easy way to write C code that can access its Git version hash?
I wrote software in C to collect scientific data in a laboratory setting. My code records the data it collects in a .yaml file for later analysis. My experiments change from day-to-day and I often have to modify the code. To keep track of revisions, I use a git...
I could do struct initialization with code:
struct struct_type_id struct_name_id = { value1, value2, value3 };
but could not with:
struct struct_type_id struct_name_id;
struct_name_id = { value1, value2, value3 };
why I could do it with the former,but could not with the latter with gcc,g++,vc2008,vc6?In other words,why the c/c++ pr...
Suppose I have an array of coordinates, representing a route. I want to decompose this route so that it contains a point, say every 5 miles. How can I do that?
struct Location
{
double latitude;
double longitude;
};
vector<Location> route;
vector<Location> computeHigherGranularityRoute(const vector<Location>& oldRoute, double ...
I'm writing a Cocoa Touch program that will (hopefully) use Libpurple as it's background. The only problem is that I have no clue where to get started. I've been looking through some source code of applications that do use it, but so far haven't gotten anywhere.
Does anyone know anything that will help me familiarize myself with libpurp...
Hello,
Visual Studio 2008
I am using the following source code that compiles ok using linux gcc 4.4.1.
However, I am trying to compile on windows xp sp3 using VS 2008 compiling as c code.
I get a run-time error on the call to vfprintf. And also the __func__ gives me a compile error. "Undeclared identifier". I thought __func__ was de...
I'm not sure if I am even barking up the right tree here... but here goes.
I'm trying to pass data from my parent process to all children. It's a simple server program that basically will keep a list of connected clients and then send the routing table of connected clients to every client. This is eventually going to include a struct of...
I have twenty or so integers which I want to be able to refer to by name when they're being set, but I would like to also be able refer to them by number like they were in an array, so I can print them out one by one using a for loop. Any ideas how to code this in C? Here's what I'm talking about in pseudo code:
/* a data structure to k...
I find myself always trying to fit everything into the OOP methodology, when I'm coding in C/C++. But I realize that I don't always have to force everything into this mold. What are some pros/cons for using the OOP methodology versus not? I'm more interested in the pros/cons of NOT using OOP (for example, are there optimization benefits ...
Hi,
i was trying to write a simple multithreaded program. It is dumping the core. I have my function that is called when a thread is created below:
void *BusyWork(void *t)
{
int i;
int *tid;
int result=0;
tid = t;
printf("Thread %d starting...\n",*tid);
for (i=0; i<10; i++)
{
result = result + (i* i);
}
...
I use code::blocks to compile my static library. The output result is a libstatic.a file.
Now, how do I link to my library to use functions that were compiled?
(I tried to use #include "libstatic.a" but my project doesn't compile)
...
this might a simple query.
when we are creating a thread we are passing the (void *)t as an argument to a function PrintHello.we are copying the value in the pointer threadid(typacasting it to long) in tid which is a long variable again.i am confused with the parameter passing.
is this a pass by reference or pass by value.over all is t...
For an assignment, I have to declare a struct as follows:
struct Food
{
char *name;
int weight, calories;
} lunch[5] = {
{
"apple", 4, 100
},
{
"salad", 2, 80
}
};
In my main, I am trying to ask the user for the rest of the inputs to fill the struct to print them out. I figure I would try to use ma...
One of the issues I have had in porting some stuff from Solaris to Linux is that the Solaris compiler expands the macro __FILE__ during preprocessing to the file name (e.g. MyFile.cpp) whereas gcc on Linux expandeds out to the full path (e.g. /home/user/MyFile.cpp). This can be reasonably easily resolved using basename() but....if you're...
I am working with a legacy C library that can be extended by writing user defined function(s) and then recompiling the source. I want to avoid the compilation requirement, and instead extend it ONCE with a function (see pseudocode below):
This function will be implemented like this:
VARIANT_TYPE CallSharedLibFunction(const char* librar...