c

String literals in C

A quick question... What is the type of string literal in C ? Is it char * or const char * or const char * const ? ...

C89: Access violation reading 0x00 (difficulty with malloc)

I am developing C89 on Visual Studio 2010 Ultimate Beta (Win 7). I don't think I'm using malloc() correctly. I am new to C, so please excuse the beginner question. The goal of my program is to count the occurrence of words in **argv using a tree. hist.c #include "tree.h" #include <stdlib.h> int main(int argc, char *argv[]) { unsi...

How can I convert my code to using getchar() putchar() instead of using scanf() and printf() for I/O?

I need to use getchar(), putchar() for I/O. My program works just fine but I cannot use it like it is in CodeWarrior for an embedded system. I also need to get rid of malloc() and just use a stack for pop/push. Can I still use strtol if I am no longer using scanf? #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX 1...

Patching a PE executable

hey everybody, lets say i've loaded a PE executable into memory and suited it with dos,nt headers structures and now i want to find out its .text/code segement actual(not VA) offset+size how do i do that? is there a win32 api for finding the .text start offset or maybe a pointer from a sturcture that points to the start offset of that s...

Can I use strtok() in a Linux Kernel Module?

I need to do a parse on the data written to my module, and the use of the strtok() function of string.h would be useful. However I've tried #include <string.h> and #include <linux/string.h> with no success. Is this possible? Or will I have to write my own strtok function? Thanks ...

C89: Any beginner mistakes in this code?

I am new to C. (I'm using C89 on Visual Studio 2010.) I wrote a little program that uses a tree to give a histogram of arguments presented to the program. Are there any obvious beginner mistakes I've make? Everything appears to run fine in my extremely limited testing. hist.c #include "tree.h" #include <stdlib.h> #include <stdio.h> in...

whats the difference between c header files(.h) and c++ header files(.hpp)

i noticed that the boost library uses header files of (.hpp). I am curious since most source files i see use normal .h header files. Could there be any special instances which warrant use of .hpp instead of .h Thanks ...

How is the @encode compiler directive implemented in Objective-C?

Can anyone explain how @encode works to extract the datatype elements present in a given object, struct, or datatype into a type definition to be used as a class descriptor for instantiation? Or maybe a pointer to some resources for learning about the implementation of new preprocessor directives? ...

Variable name conflict with GDB debugger

I'm debugging a C++ program with GDB on Linux, and I need to see the value of a member variable while the program is running. The member variable, unfortunately, is named list, which happens to be a GDB keyword. So when I try: print m_operations.m_data[10].m_data.list I get... A syntax error in expression, near list'. I tried all s...

Does using large libraries inherently make slower code?

I have a psychological tic which makes me reluctant to use large libraries (like GLib or Boost) in lower-level languages like C and C++. In my mind, I think: Well, this library has thousands of man hours put into it, and it's been created by people who know a lot more about the language than I ever will. Their authors and fan...

find string of N 1-bits in a bit-array

As the title sais I want to find a successive run of n one-bits in a bit-array of variable size (M). The usual use-case is N <= 8 and M <= 128 I do this operation a lot in an innerloop on an embedded device. Writing a trivial implementation is easy but not fast enough for my taste (e.g. brute force search until a solution is found). I...

How can I build a C/C++ program using `static linking` & `Dynamic linking` with gcc & Visual studio?

A library can be used in an application in two ways: Statically-linked Dynamically-linked But how to do that using both Visual Studio (windows) & GCC? I know libraries are distributed only in these 4 ways: Source header-only libraries *.lib files for windows. *.a for linux *.dll (windows) & *.so (linux). Source distribution is j...

Little endian Vs Big endian

Lets say I have 4Byte integer and I want to cast it to 2Byte short integer. Am I right that in both (little and big endian) short integer will consist of 2 least significant bytes of this 4Byte integer? Second question: What will be the result of such code in little endian and big endian processor? int i = some_number; short s = *(...

Find duplicates in array.

Assume you are given two arrays of integers of constant length which is 3, and you are always sure that two elements of the given two arrray will have same values. so assume array A has three values: a, b, c. and array B has three values: d, e, f. we are sure that two of the values will be same. we are asked to put these four different...

is local static variable provided by embedded compilers?

im working on a c lib which would be nice to also work on embedded systems but im not very deep into embedded development so my question are most embedded compilers able to cope with local static variables - which i would then just assume in further development OR is there a #define which i can use for a #ifdef to create a global variab...

read strings from an image file in C

hi I'm trying to read only the strings from an image file. I was able to successfully read all the strings in the image file using java. I wrapped the inputstream into a filereaderstream which is again wrapped inside of a bufferereader. so now i can extract all the strings from the image file (like xmp tags and exif, tiff tags etc) .. ...

Dynamic allocation (malloc) of contiguous block of memory

For an assignment, I have to allocate a contiguous block of memory for a struct, but I'm first trying to do it with a 2D array of ints first and see if I understand it correctly. We had an example in the book that creates a block of memory for the pointer array (rows), and then initializes the cols and points the pointer to them. This ...

Is there an easy way to concatenate string non-literals with literals?

I would like to be able to do this: lcd_putc("\fDeposited $" & disp_money & "\nAdd $" & temp & " more"); Unfortunately, the string literals and non-literals don't concatenate that easily. I know how to concatenate two literals, and how to concatenate two non-literals (with strcat) but that's not really what I'm looking for. Can anyo...

What would a script to replace \ with / in many files look like?

Yes, this is a really lazy question but I figure this is problem that people have often enough that someone here would have something already written to share. I have a ton of C files with #include statements using Windows relative paths. I'm working on compiling the code on other operating systems (immediately, on my OS X development m...

absolute Value of double

I am trying write a function named absD that returns the absolute value of its argument. I do not want to use any predefined functions. Right now i am getting a parse error when i try to compile it. I would image all i would have to do to get the absolute value of a double is change the sign bit? this is what i have #include <stdio.h> ...