c

Realloc Problem

Thank you for looking, please ignore - all sorts of shenanigans are happening and I am trying to debug more. ===================================== Can anyone explain this behavior of realloc? Output: before realloc start: testing%20encryp before realloc app: ' ' realloc size: 27 after realloc: testing%20e strlen(newstr): 11 ...

Beginner Doing K&R

Hi, I'm just starting programming and going through K&R to try and learn C. I've gotten to the section on command line arguments (5.10) but now I'm stumped. Every time I try and open a program I've written with command line arguments I'm told that file X, X being the argument, doesn't exist. `gcc -o find find.c open find test The f...

General way to manipulate the times (between timezones) in C ?

After writing a sample code for the question about converting between timezones, one of the comments to it was the need for more general method for converting from timezone A to timezone B. I was curious myself too to have a more high-level primitives for such a manipulations, so I wrote the below code. One drawback I see is that it con...

C: Function returning via void *

Coming from Java I'm confused by the use of Void allowing a return value in the following: void *emalloc(size_t s) { void *result = malloc(s); if (NULL == result) { fprintf(stderr, "MEMORY ALLOCATION FAILURE\n"); exit( EXIT_FAILURE ); } return result; } Is this returning a pointer to a chuck o...

How do I replace multiple spaces with a single space in C?

Well I'm looking for a function that reduce multiple spaces in a string. For example for string s given : s="hello__________world____!" The function must return "hello_world_!" In python we can do it via regexp simply as: re.sub("\s+", " ", s); ...

Creating Core Foundation classes

Since I can't seem to find any documentation on this subject, is it possible to create your own Core Foundation "class"? (classes as in ones that can be used with CFRetain() and CFRelease) I want to take advantage of the polymorphic capabilities and object inspection built into Core Foundation without the overhead of Objective-C or creat...

shared library file size

On creating a shared library the ./sl file size is coming out to be greater than 60KB. There are 2 .o files whose total size is over 20KB. Checked the utlities : ldd and elfdump to determine libraries being referenced. Apart from the original files used I see references of :/usr/ccs/lib/pa20_64/lddstub and SOURCE FILE INFO: movelr1 PA...

bash script 'here strings'

I am going to be running a C program from inside a bash script. The c program expects inputs from the user. total number of inputs are 7. which are on 7 different lines. for example Please enter input1: 1 Please enter input2: 2 Please enter input3: 3 so on.. I did some reading up and found out that bash here strings are used for ...

Arbitrary-precision arithmetic Explanation

I'm trying to learn C and have come across the inability to work with REALLY big numbers (i.e., 100 digits, 1000 digits, etc.). I am aware that there exist libraries to do this, but I want to attempt to implement it myself. I just want to know if anyone has or can provide a very detailed, dumbed down explanation of arbitrary-precision a...

Why do some compilers use "a.out" as the default name for executables?

Most UNIX C compilers link executables by default to a file called "a.out". Why? Is this a written standard or just de-facto standard behavior? What would break if these compilers would just produce an error message (or use a different default name) instead of producing "a.out"? ...

What's the difference between %c and %C in printf?

I can only find references for small c. I assume that the capital C is for Unicode, but I'm not sure. For lower numbers, both output the same character. ...

Why is mysql_num_rows returning zero?

I am using C MySQL API int numr=mysql_num_rows(res); It always returns zero, but in my table there are 4 rows are there. However, I am getting the correct fields count. what is the problem? Am i doing anything wrong? ...

Win32 API CopyFile() fails to send multiple files

While attempting to use the CopyFile() function I have encountered a strange error. It will write neither of the files to my destination. Here is the code. The section when I send files has been commented. Keep in mind this code is a rough draft so ignore the function definitions. /* BrowserFind.c Version 0.2 07/29/09 LogicKills ...

Implementing condition variables for CRITICAL_SECTIONs for Winthreads for XP

I have a desire for POSIX style condition variables on Win32. I have some code that needs to run on XP, so I can't use Vista/Server 2008's CONDITION_VARIABLE. It makes use a of a pseudo condition variable class currently, which is based on leaving the critical section and signaling an auto reset event for signaling / waking. For waitin...

Refactoring policy for real-time code for critical system

I'm working in a company which produce real-time C program for home-made hardware, the program is 15-years old, and still need to be maintained. Even though we do not verify manually the code, We have a strict no-refactoring policy. Even if a certain code is hard to grasp, or have many clear code smells, you must make minor changes to i...

size of a datatype without using sizeof

Hi all I have a datatype say X and I want to know its size without declaring a variable or pointer of that type and of course without using sizeof operator. Is this possible. I thought of using standard header files which contain size and range of datatypes but that doesn't work with user defined datatype. Any help will be appreciated. ...

How to start off with ARM processors?

Is it advisable to directly start off with the datasheet and user manual of an ARM processor for a newbie or first get an idea about the ARM world and then go ahead? ...

C : How do you simulate an 'exception' ?

I come from a C# background but I'm currently learning C atm. In C#, when one wants to signal that an error has occurred, you throw an exception. But what do you do in C ? Say for example you have a stack with push and pop functions. What is the best way to signal that the stack is empty during a pop ? What do you return from that f...

Portable thread-safety in C?

Purpose I'm writing a small library for which portability is the biggest concern. It has been designed to assume only a mostly-compliant C90 (ISO/IEC 9899:1990) environment... nothing more. The set of functions provided by the library all operate (read/write) on an internal data structure. I've considered some other design alternatives,...

using unions in function parameters

I recently discovered that something compiles(not sure that it's legal though). My need for such a thing comes from this: My project outputs machine code for a selected arch.(which may or may not be the same arch. as the one running the program). So, I would like to support up to 64bit architectures right now(while also supporting existi...