Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 C


  VIM Plugins for C/C++ developers

Following up on my previous post on Essential Vim Plugins for Web Developers, I have decided to tell you about the awesomeness of the C / C++ plugin for Vim in this article.Now to get things going, let’s start by thinking what are the basic stuffs that you would be carrying out as a C / C++ developer? Include header files, some functions, loops, conditional statements and a main function. These are some repetitive boring tasks that you would rather have someone else do it for you. Well, that’s what c.vim plugin is all about.For example, after installing this plugin, when you...

7,179 0       C PLUGIN C++ DEVELOPER VIM VIM FOR C


  Read white space with scanf()

Usually, when we want to enter string with white spaces in C, we need to call gets() or fgets(0 method. We usually will not use scanf(0 or fscanf() because they cannot accept white spaces when scan user inputs. But when we specify the format in scanf() function, we may read strings with white space. the code section below illustrate this:#include <stdio.h> int main(int argc,char **argv){       char name[30];    fprintf(stdout,"Please enter the name : \n");fscanf(stdin,"%[^\n]s",name); fprintf(stdout,"%s\n",name); return 0;} On a...

19,460 0       C SCANF WHITE SPACE STRING FORMAT


  Pointers, arrays, and string literals

A recently posted question on Stack Overflow highlighted a common misconception about the role of pointers and arrays held by many programmers learning C.The confusion stems from a misunderstanding concerning the role of pointers and strings in C. A pointer is an address in memory. It often points to an index in an array, such as in the function strtoupper in the following code:void strtoupper(char *str){ if (str) { // null ptr check, courtesy of Michael while (*str != '\0') { // destructively modify the contents at the current pointer location ...

2,766 0       CHAR POINTER INITIALIZATION LITERAL CANN


  The most stupid C bug ever

I have been programming for a number of years already. I have seen others introduce bugs, and I have also introduced (and solved!) many bugs while coding. Off-by-one, buffer-overflow, treating pointers as pointees, different behaviors or the same function (this is specially true for cross-platform applications), race conditions, deadlocks, threading issues. I think I have seen quite a few of the typical issues.Yet recently I lost a lot of time to what I would call the most stupid C bug in my career so far, and probably ever.I am porting a Unix-only application which uses tmpfile() to create te...

2,156 0       C BUG STUPID BUG CODE ALL


  Getting started with C++ TR1 regular expressions

Overview This article is written for the benefit of someone familiar with regular expressions but not with the use of regular expressions in C++ via the TR1 (C++ Standards Committee Technical Report 1) extensions. Comparisons will be made with Perl for those familiar with Perl, though no knowledge of Perl is required. The focus is not on the syntax of regular expressions per se but rather how to use regular expressions to search for patterns and make replacements. Support for TR1 extensions in Visual Studio 2008 is added as a feature pack. It is also included in Visual Studio 2010. Other im...

4,045 0       EXTENSION REGULAR EXPRESSION REPLACE TR1


  template function in class in C++

We can define template function in a class, but one thing we should pay attention to is that the member function template definition (in addition to the declaration) should be in the header file, not the cpp, though it does not have to be in the body of the class declaration itself.Example //Sorter.h#pragma onceclass Sorter{public:    Sorter(void);    ~Sorter(void);    template <class type> static void qsort(type arr[],int start,int end);};template <class type> static void Sorter::qsort(type arr[],int start,int end){    in...

2,603 0       C++ TEMPLATE FUNCTION CLASS DEFINITION D


  memcpy() vs memmove() in C

memcpy() copies the bytes of data between memory blocks. If the block of memory overlaps, the function might not work properly. Use memmove() to deal with overlapping memory blocks. memmove() is very much like memcpy() but very flexible as it handles overlapping of memory blocks. example : char msg[50] = "abcdefghijklmnopqrstuvwxyz"; char temp[50]; main() { strcpy(temp, msg); printf("Original Msg = %s\n",temp); memcpy(temp+4, temp+16, 10); printf("After memcpy without overlap = %s\n",temp); strcpy(temp , msg); memcpy(temp+6, temp+4, 1...

11,007 0       COMPARISON MEMORY MEMCPY MEMMOVE C DIFFE


  Converting Decimal Fractions to Binary

Converting Decimal Fractions to BinaryIn the text proper, we saw how to convert the decimal number 14.75 to a binary representation. In this instance, we \"eyeballed\" the fractional part of the binary expansion; 3/4 is obviously 1/2 + 1/4. While this worked for this particular example, we\'ll need a more systematic approach for less obvious cases.In fact, there is a simple, step-by-step method for computing the binary expansion on the right-hand side of the point. We will illustrate the method by converting the decimal value .625 to a binary representation..Step 1: Begin with the decimal frac...

4,590 0       DECIMAL FRACTIONAL BINARY