<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>C Programming on Guowei Lv</title>
    <link>https://www.lvguowei.me/categories/c-programming/</link>
    <description>Recent content in C Programming on Guowei Lv</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Thu, 08 Aug 2019 20:36:01 +0300</lastBuildDate><atom:link href="https://www.lvguowei.me/categories/c-programming/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>How Scanf Works</title>
      <link>https://www.lvguowei.me/post/how-scanf-works/</link>
      <pubDate>Thu, 08 Aug 2019 20:36:01 +0300</pubDate>
      
      <guid>https://www.lvguowei.me/post/how-scanf-works/</guid>
      <description>scanf is essentially a &amp;ldquo;pattern matching&amp;rdquo; function that tries to match up groups of input characters with conversion specifications.
An Example No blah blah blah, let&amp;rsquo;s see an example.
int i, j; float x, y; scanf(&amp;#34;%d%d%f%f&amp;#34;, &amp;amp;i, &amp;amp;j, &amp;amp;x, &amp;amp;y); // input // &amp;lt;space&amp;gt;&amp;lt;space&amp;gt;1-20.3-4.0e3&amp;lt;ret&amp;gt;  Here is how scanf would process the new input:
 Skips the leading 2 spaces. Conversion specification: %d. The first nonblank input character is 1; since integers can begin with 1, scanf then reads the next character, -.</description>
    </item>
    
    <item>
      <title>C Programming - A Modern Approach</title>
      <link>https://www.lvguowei.me/post/c-programming-a-modern-approach-recommend/</link>
      <pubDate>Sat, 09 Mar 2019 22:33:07 +0200</pubDate>
      
      <guid>https://www.lvguowei.me/post/c-programming-a-modern-approach-recommend/</guid>
      <description>I&amp;rsquo;m brushing up my C now using the book C Programming - A Modern Approach by K.N.King.
 I have the classic K&amp;amp;R book, I do not recommend it. I just find it very hard to read, no matter if you are a novice or a veteran.
After some googling on people&amp;rsquo;s recommendations, I got the K.N.King book. I&amp;rsquo;m glad that I did. Very easy to read, has a good set of exercises and programming projects.</description>
    </item>
    
    <item>
      <title>Practical C - Stack</title>
      <link>https://www.lvguowei.me/post/practical-c-stack/</link>
      <pubDate>Sat, 11 Aug 2018 20:42:34 +0300</pubDate>
      
      <guid>https://www.lvguowei.me/post/practical-c-stack/</guid>
      <description>In this blog post, let&amp;rsquo;s implement a generic stack in C.
We will do this by several iterations, from simple version to the full blown version step by step.
An Integer Version Let&amp;rsquo;s start with implementing an integer stack.
#include &amp;lt;assert.h&amp;gt;#include &amp;lt;stdio.h&amp;gt;#include &amp;lt;stdlib.h&amp;gt; typedef struct { // int array to store elements of the stack  int *elems; // the actual length of the stack  int logicalLen; // the allocated length of the array  int allocLen; } stack; // Initialize a stack void StackNew(stack *s); // Dispose a stack void StackDispose(stack *s); // Push an element onto the stack void StackPush(stack *s, int value); // Pop an element from the stack int StackPop(stack *s); void StackNew(stack *s) { // allocate 4 elements for the array  s-&amp;gt;elems = (int *)malloc(4 * sizeof(int)); s-&amp;gt;allocLen = 4; s-&amp;gt;logicalLen = 0; } void StackDispose(stack *s) { free(s-&amp;gt;elems); } void StackPush(stack *s, int value) { if (s-&amp;gt;logicalLen == s-&amp;gt;allocLen) { // double the size of the array if there is no free space in it  s-&amp;gt;elems = (int *)realloc(s-&amp;gt;elems, 2 * s-&amp;gt;allocLen * sizeof(int)); s-&amp;gt;allocLen *= 2; } s-&amp;gt;elems[s-&amp;gt;logicalLen] = value; s-&amp;gt;logicalLen++; } int StackPop(stack *s) { assert(s-&amp;gt;logicalLen !</description>
    </item>
    
    <item>
      <title>Practical C - Linear Search</title>
      <link>https://www.lvguowei.me/post/lsearch-in-c/</link>
      <pubDate>Sun, 05 Aug 2018 23:06:09 +0300</pubDate>
      
      <guid>https://www.lvguowei.me/post/lsearch-in-c/</guid>
      <description>I start this blog series to show some of the trickier parts of C programming.
In the first post, let&amp;rsquo;s implement the linear search in C.
Integer Version Let&amp;rsquo;s imagine that we search on an integer array.
 Two things to notice here:
 The function needs the array size n as a separate parameter. Only the array&amp;rsquo;s address is passed in the function.  Generic Basic Version Let&amp;rsquo;s write a more generic version that does not specify type.</description>
    </item>
    
    <item>
      <title>Generic Programming in C</title>
      <link>https://www.lvguowei.me/post/generic-programming-in-c/</link>
      <pubDate>Wed, 27 Dec 2017 21:43:47 +0200</pubDate>
      
      <guid>https://www.lvguowei.me/post/generic-programming-in-c/</guid>
      <description>Generic programming is an important idea in programming. In languages like Java and C++, it can be done easily. In this post, I show how to do it in plain old C.
We use the classic stack implementation. First, we implement an int version.
This is stack.h:
typedef struct { int *elems; int logLength; int allocLengh; } stack; void StackNew(stack *s); void StackDispose(stack *s); void StackPush(stack *s, int value); int StackPop(stack *s); This is stack.</description>
    </item>
    
  </channel>
</rss>
