c

char Array problem in C

char label[8] = "abcdefgh"; char arr[7] = "abcdefg"; printf("%s\n",label); printf("%s",arr); ====output========== abcdefgh abcdefgÅ Why Å is appended at the end of the string arr? I am running C code in Turbo C ++. ...

Create jnilib from x86_64 .a files on Mac OS X 10.6

I want to use a bunch of non-universal (thin?), x86_64, C libraries from a Java application. The problem is that I only have static versions of them (.a files) and the jvm needs them to be dynamic. I tried using libtool to combine the files into a single dynamic library but I just got error messages saying that many of the symbols (poss...

mysql java versus c program, difference in characters stored.

Hello, I have two programs- First one being a C program that writes in to mysql database. Second is a java program that reads the data from mysql database. The C program reads list of files in a particular directory and inserts the file names in DB. The Java program reads these rows and tries to do some file processing using these fil...

Does fgets() always terminate the char buffer with \0?

Does fgets() always terminate the char buffer with \0 even if EOF is already reached? It looks like it does (it certainly does in the implementation presented in the ANSI K&R book), but I thought I would ask to be sure. I guess this question applies to other similar functions such as gets(). EDIT: I know that \0 is appended during "nor...

How can I debug St9bad_alloc failures in gdb in C?

I have a program failing with: terminate called after throwing an instance of 'std::bad_alloc' what(): St9bad_alloc I imagine it's something to do with malloc/free, but I don't know which one. What breakpoint can I in gdb set that will break on the error so that I can view a stack trace? The program is a combination of C and C++,...

How to check which process initiated sys_open

I'm taking a course in operating systems and we work in Linux (Red hat 8.0). I'm trying to implement a file open,close tracker that will save for every process a history of files it opens and closes. I expected sys_open,close to also accept the process id and that I could use that to access the history of the process that initiated the c...

initializing char pointers

Hello, gcc 4.3.3 I am just wondering if this is good practice. I have a char pointer which would be used to store a string. It is used later in the program. I have declared and initialized like this: char *mgt_dev_name = NULL; Many thanks for any advice, ...

What limits my use of the stack in terms of memory?

In windows (or any other OS for that matter) what determines how much stack I can use? The name of this very website makes me assume it's possible to run out of stack so should I avoid putting large amounts of data on the stack? ...

Writing / Reading Value to an Array in C

I must be going insane. This is incredibly simple so I am apparently overlooking something: Here is my code: int salesarray[20]; scanf("%d",&sales_input); printf("sales_input is %d",sales_input); salesarray[i] = sales_input; printf("salesValue is %d",i,salesarray[i]); Here is what I will see: sales_input is 2salesV...

Basics Question: Best Practices concerning Posix Threads and Dynamic Memory

Is it advisable or even possible to have a dynamically growing array of structs fed and read by different concurrently running posix threads? Where do I have to look for best practices for applications of that sort - are there any which are "common wisdom"? I am new to this area and would need some initial pointers for where to start and...

How does C Handle Integer Literals with Leading Zeros, and What About atoi?

When you create an integer with leading zeros, how does c handle it? Is it different for different versions of C? In my case, they just seem to be dropped (but maybe that is what printf does?): #include <stdio.h> int main() { int a = 005; printf("%i\n", a); return 0; } I know I can use printf to pad with 0s, but I am jus...

How do I get the full path for a filename command-line argument?

I've found lots of libraries to help with parsing command-line arguments, but none of them seem to deal with handling filenames. If I receive something like "../foo" on the command line, how do I figure out the full path to the file? ...

Does Solaris cc embed in an executable differing info for different compiles ?

G'day, This has been asked before for VC++ but I am interested in the answer for Solaris. I'm compiling and linking the following trivial C code: #include <stdio.h> int main() { printf("Hello world!\n"); return 0; } using the command: cc -o hello1 hello.c and doing this a couple of times to get executables hello2 and hel...

Using enum in Objective-C?

Is this the correct (or even a valid way) to use emums in Objective-C? i.e. The menuItem is not used but just defines a list add=1, load=2, list=3 etc. enum menuItems {add = 1,save,load,list,removeAll,remove,quit}; int optionSelect; scanf("%d", &optionSelect); switch (optionSelect) { case add: ... break; cheers gary ...

C all type parameter

How can I write a function which accepts a parameter of a generic type in C? (such as an int, a char...) ...

looping through enum values

Is it possible to loop through enum values in Objective-C? ...

NSString no 'assign', 'retain', or 'copy' attribute is specified

I'm declaring an NSString property in a class and objective-c is complaining that: NSString no 'assign', 'retain', or 'copy' attribute is specified It then casually lets me know that "assign is used instead". Can someone explain to me the difference between assign, retain and copy in terms of normal C memory management functions? ...

undefined reference to pthread_create in linux (c programming)

I'm interested in learning to write C programs which use threads. I picked up the following demo off the web from https://computing.llnl.gov/tutorials/pthreads/ #include <pthread.h> #include <stdio.h> #define NUM_THREADS 5 void *PrintHello(void *threadid) { long tid; tid = (long)threadid; printf("Hello World! It's me, thre...

Can a variable be used to define the size of an array on the stack in c?

I have a situation where I want my program to read in some numbers that will define the size of a two dimensional array (used as a matrix). I originally argued that the only way to do this would be to use a malloc call to put the array on the heap, something like this: matrixElement* matrix = malloc(sizeof(matrixElement) * numRows * num...

Give me an assignment in C

I am teaching myself C, with several books as well as online tutorials. I am in the middle of Greg Perry's book Absolute Beginner's Guide to C. I know I learn best by doing, so I need to start writing my own code. My problem is that I am a little stymied by not being able to come up with ideas for programs that will exercise my skills a...