ODBC Under Linux
Hello All,
I am trying to write an app. which will have to access a database. I wanted
to write the app so that the backend database could be changed without changing the app. I know there is ODBC out there, but I was wondering if anyone had ideas on the best free ODBC, or maybe some better way of doing this.
Thanks
Chuck
Quoted 5 lines · [email protected] wrote:
Hello All,
I am trying to write an app. which will have to access a database. I wanted
to write the app so that the backend database could be changed without changing the app. I know there is ODBC out there, but I was wondering if anyone had ideas on the best free ODBC, or maybe some better way of doing this.
I don't know about "best", but the two most popular ODBC managers are iODBC and unixODBC:
http://www.iodbc.org/ http://www.unixodbc.org/
Signature · 1 line
Glynn Clements <[email protected]>
How to open a file and to disable other processes from removing it
Hello to everyone,
Can somebody tell me how to open a file on Linux and to disable other processes from being capable to remove it?
Regards, Alex
Re: How to open a file and to disable other processes from removing it
Quoted 2 lines · Alexi Jordanov
Can somebody tell me how to open a file on Linux and to disable other processes from being capable to remove it?
1. Nothing will prevent root-owned processes from deleting the file. Anything which you do to prevent it can be undone by root.
2. Unless the process which creates the file is running as root, nothing will prevent other processes which run under the same account from deleting it.
If the process which creates the file is running as root, then you can create the file in a directory which has the sticky bit set, whose owner differs from that of the file, and which has no permissions for anyone other than the directory's owner. The sticky bit ensures that no-one other than the owner can delete it, and the lack of permissions for the file's owner on the parent directory ensures that the file's owner cannot reference it (and hence can't delete it).
Signature · 1 line
Glynn Clements <[email protected]>
dynamic allocation of array of structures
Hello,
struct {
char *name;
int telnr;
} people[100];
Instead of statically allocating an array of 100 of these structures like I have done, I want to dynamically allocate the array at run-time and resize the number of structures some where at any time in the main program.
I know how to resize char arrays and int arrays but I never (re)sized an array of structres which can be accessed with something as: ``people[4].name''. In Google nothing really usefull turns up.
Can this be done without having to resort to other implementations like linked lists etc.. ? If so how ?
Thank you in advance.
J.
RE: dynamic allocation of array of structures
typedef struct Apeople {
char *name;
int telnr;
} Tpeople;
...
Tpeople *toto;
toto = (Tpeople *)(malloc (sizeof Tpeople) * <the number of elements you want to allocate>);
But I think that you were searching a "proper way" to implement it, isn't it :?
A.N.
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of J.
Sent: Saturday, March 22, 2003 8:48 PM
To: [email protected]
Hello,
struct {
char *name;
int telnr;
} people[100];
Instead of statically allocating an array of 100 of these structures like I have done, I want to dynamically allocate the array at run-time and resize the number of structures some where at any time in the main program.
I know how to resize char arrays and int arrays but I never (re)sized an array of structres which can be accessed with something as:
``people[4].name''.
In Google nothing really usefull turns up.
Can this be done without having to resort to other implementations like linked lists etc.. ? If so how ?
Thank you in advance.
J.
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: dynamic allocation of array of structures
Quoted 9 lines · Anthony Nguyen
typedef struct Apeople {
char *name;
int telnr;
} Tpeople;...
Tpeople *toto;
Quoted 7 lines
toto = (Tpeople *)(malloc (sizeof Tpeople) * <the number of elements you want to allocate>);
But I think that you were searching a "proper way" to implement it, isn't it :?
A.N.
Lol :) euh ... to be honest .. actually yes ..
Of course before I decided to send a message to this list I have tried something like you described above, but it doesn't work quitte as I expected or better said, like I want it to work.
Maybe some of you could give a hunch what goes wrong. (Code compiles without Complaining)
#include <stdio.h>
#include <stdlib.h>
typedef struct {
char initial;
int roomnr;
} record;
int main(void) {
int i = 0;
record *ptr;
if((ptr = (record *)malloc(10 * sizeof(record))) == NULL) {
fprintf(stderr, "Error: failed malloc\n"); return 1;
}
for(i = 0; i < 10; i++, ptr++) {
ptr->initial = 'A' + i;
ptr->roomnr = i;
}
for(i = 0; i < 10; i++, ptr++) {
printf("ptr->initial = %c, ", ptr->initial);
printf("ptr->roomnr = %d\n", ptr->roomnr);
}
return 0;
}
Thnkx.. J.
Re: dynamic allocation of array of structures
Quoted 1 line · J.
Maybe some of you could give a hunch what goes wrong.
You should use linked lists. The code below can work if you save the starting offset of you elements, but in general it is not safe.
Quoted 10 lines
#include <
stdio.h>
#include <stdlib.h>typedef struct {
char initial;
int roomnr;
} record;int main(void) {
int i = 0;
- record *ptr;
+ record *ptr, *t;
Quoted 4 lines
if((ptr = (record *)malloc(10 * sizeof(record))) == NULL){
fprintf(stderr, "Error: failed malloc\n"); return 1;
}
+ t = ptr;
Quoted 4 lines
for(i = 0; i < 10; i++, ptr++){
ptr->initial= 'A' + i;
ptr->roomnr= i;
}
+ ptr = t;
Quoted 7 lines
for(i = 0; i < 10; i++, ptr++){
printf("ptr->initial = %c, ", ptr->initial);
printf("ptr->roomnr = %d\n", ptr->roomnr);
}return 0;
}
Elias
Signature · 2 lines
University of Athens I bet the human brain Physics Department is a kludge --Marvin Minsky
Re: dynamic allocation of array of structures
Quoted 10 lines · J.
struct {
char *name;
int telnr;
} people[100];Instead of statically allocating an array of 100 of these structures like I have done, I want to dynamically allocate the array at run-time and resize the number of structures some where at any time in the main program.
Quoted 6 lines
I know how to resize char arrays and int arrays but I never (re)sized an array of structres which can be accessed with something as: ``people[4].name''. In Google nothing really usefull turns up.
Can this be done without having to resort to other implementations like linked lists etc.. ? If so how ?
Use malloc() and realloc(), i.e.
ptr = malloc(count * sizeof(record)); and: ptr = realloc(ptr, count * sizeof(record));
Quoted 3 lines · Elias Athanasopoulos
Quoted 1 line
Maybe some of you could give a hunch what goes wrong.
You should use linked lists.
I can't see any reason to use linked lists here.
Quoted 2 lines
The code below can work if you save
the starting offset of you elements, but in general it is not safe.
[snip]
Quoted 8 lines
+ t = ptr;
Quoted 4 lines
for(i = 0; i < 10; i++, ptr++){
ptr->initial= 'A' + i;
ptr->roomnr= i;
}+ ptr = t;
It's better to just leave the original pointer alone, and work on the copy, e.g.
for(i = 0, t = ptr; i < 10; i++, t++) {
t->initial = 'A' + i;
t->roomnr = i;
}Actually, using explicit pointer increment operations for array iteration is a throwback to the days before compilers commonly performed loop induction optimisation.
Nowadays, you may as well just write:
for(i = 0; i < 10; i++) {
record *t = &ptr[i];
t->initial = 'A' + i;
t->roomnr = i;
}Leave the induction up to the compiler; it's less likely to get it wrong than a programmer is.
Signature · 1 line
Glynn Clements <[email protected]>
RE: dynamic allocation of array of structures, Thnkx..
In reply to J.I got the picture and everything works fine now.
I learned something again...
Merci.
J.