C/C++开发学习

C/C++开发学习

本文的目的是将C语言相关的重要知识点串联起来,启动抛砖引玉的作用,具体例子是临时设计的

函数输入输出基础

宏定义获取最小值
写入文件对文件进行操作
见例子部分

算法之冒泡排序

见例子部分
怎样实现冒泡排序的升序和降序通过函数指针调用?

数据结构之链表

怎样实现链表结构并且能够添加节点和进行链表的遍历和释放

递归调用

见例子部分
怎样用递归调用实现编写阶乘?

C语言例子程序

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/**
  目的:练习C语言基本的知识点
  内容:主要包括1.交换数据函数输入输出 2.算法中的冒泡排序 3.递归调用 4.数据结构中的链表添加遍历 5.文件写入 6.函数指针和回调
  7.结构枚举宏定义 8字符串库函数的使用
  面试相关:与零值的比较 memcpy的使用 位操作 函数返回指针(不能局部除非static) typedef  数组退化 位操作
  */

#define NUM1 20
#define NUM2 40

#define MIN(a,b) ((a)<(b)?(a):(b))

static int count = 0;

struct node {
    int a;
    struct node* next;
};

struct node* head = NULL;
struct node* end = NULL;

void addlist(int a) {
    struct node *newnode = (struct node*)malloc(sizeof(struct node));
    newnode->a = a;
    newnode->next =NULL;
    if(head == NULL) {
        head = newnode;
        end = newnode;
    }
    else {
        end->next = newnode;
        end = newnode;
    }
}

void scanlist() {
    struct node* tmp = head;
    while(tmp!=NULL) {
        printf("in list %d\n",tmp->a);
        tmp = tmp->next;
    }
}

void freelist(){
    struct node *tmp = head;
    while(tmp!=NULL) {
        struct node *fp = tmp;
        tmp = tmp->next;
        printf("in list free %d\n",fp->a);
        free(fp);
    }
}

void swap1(int *a,int *b) {
    int tmp = *a;
    *a = *b;
    *b = tmp;

    count++;
    printf("count is %d\n",count);
}

void sort1(int *arr,int lengh) {
    int i=lengh-1;
    for(;i>0;i--) {
        int j=0;
        for(;j<i;j++) {
            if(arr[j]>arr[j+1]) {
                swap1(&arr[j],&arr[j+1]);
            }
        }
    }
}

void sort2(int *arr,int lengh) {
    int i=lengh-1;
    for(;i>0;i--) {
        int j=0;
        for(;j<i;j++) {
            if(arr[j]<arr[j+1]) {
                swap1(&arr[j],&arr[j+1]);
            }
        }
    }
}

int* sort3(int *arr,int lengh) {
    int i=lengh-1;
    for(;i>0;i--) {
        int j=0;
        for(;j<i;j++) {
            if(arr[j]<arr[j+1]) {
                swap1(&arr[j],&arr[j+1]);
            }
        }
    }
    return arr;
}

void writeText(int *aar) {
FILE *fl;
fl = fopen("a.txt","a");

int i =0;
fputs("print start\n",fl);
for(;i<6;i++) {
    fprintf(fl,"arr[%d] = %d\n",i,aar[i]);
}
fputs("print end\n",fl);
fclose(fl);
}

int digui(int a) {
    if(a==1)
        return 1;
    return a*digui(a-1);
}

typedef enum DAY {
    first=18,second,third,fouth
} day;

int main(void)
{
    int a,b;
    printf("please input like int,int\n");
    scanf("%d,%d",&a,&b);
    swap1(&a,&b);
    printf("a = %d\n",a);

    day myday;
    myday = first;
    int arr[]  = {NUM1,NUM2,myday,67,39,22};

    void (*sort)(int *a,int b) = sort1;
    sort(arr,6);
    int i=0;
    for(;i<6;i++) {
        printf("arr[%d] = %d\n",i,arr[i]);
    }

    writeText(arr);

    int result = digui(4);
    printf("digui result is %d\n",result);

    addlist(5);
    addlist(6);
    scanlist();
    freelist();

    printf("MIN(66,88) = %d\n",MIN(66,88));

    char dest[6];
    strcpy(dest,"testStrcpy");
    printf("dest is %s\n",dest);

    float EX = 0.000001;
    float fl = 0.0001;
    if (fl>=-EX && fl<=EX) {
        printf("fl is zero\n");
    } else {
        printf("fl is not zero\n");
    }

    struct node mynode;
    struct node srcnode;
    srcnode.a = 6;
    srcnode.next = NULL;
    memcpy(&mynode,&srcnode,sizeof(srcnode));
    printf("memcpy test is %d\n",mynode.a);

    int intarr[] = {4,5,6,7,8,9};
    printf("sizeof(intarr) test is %d\n",sizeof(intarr));//intarr作为参数则退化成指针大小为4个字节

    int j=0;
    int *tmp = sort3(intarr,6);
    for(;j<6;j++) {
        printf("intarr[%d] = %d\n",i,tmp[j]);
    }

    unsigned int bit = 60; //60 = 0011 1100
    printf("~bit 60 is %d\n",~bit);
    printf("bit<<2 is %d\n",bit<<2);

    return 0;
}

项目地址:https://github.com/xuexiangqian12345/tradeCLanguage.git

C语言相关网站书籍

网站:
菜鸟编程:适合简单快速入门
C语言中文网
C语言网:在线学习练习
牛客网
C Primer+Plus 第6版 中文版
C 程序设计语言
C 专家编程
C 和指针
C 陷阱与缺陷
​ 高质量程序设计指南 C语言
深入理解C指针

C语言阅读笔记

菜鸟编程笔记

C++语言刻意练习

#include <iostream>
#include <cstring>
#include <fstream>

using namespace std;

// 基类
class Shape
{
   public:
      void setWidth(int w)
      {
         width = w;
      }
      void setHeight(int h)
      {
         height = h;
      }
      virtual int area() {
          cout<<"in shap "<<endl;
          return 0;
      }

   protected:
      int width;
      int height;
};

// 派生类
class Rectangle: public Shape
{
   public:
      int getArea()
      {
         cout<<"Area is"<<width*height<<endl;
         return (width * height);
      }
      int area() {
          cout<<"in Reactangle "<<endl;
          return 0;
      }
};

// 声明一个结构体类型 Books
struct Books
{
   char  title[50];
   char  author[50];
   char  subject[100];
   int   book_id;
   void testStruct();
};

namespace xxq_space {
//函数模块(类模板)
template<class T>
//template<typename T>
void swap(T &a,T &b) {
    if(a==0||b==0) {
        throw "a or b is zero";
    }
    cout<<"start swap a and b"<<endl;
    T tmp = a;
    a = b;
    b = tmp;
}

void printTest() {
    char name[50];
    cin >> name;
    cout<<"name is "<<name<<endl;
}

}

int main()
{
    Shape *shap;//使用指针才生效
    Rectangle rectangle;
    rectangle.setHeight(6);
    rectangle.setWidth(8);
    rectangle.getArea();

    shap = &rectangle;
    shap->area();


    ofstream outfile;
    char data[100];
    outfile.open("a.txt");
    cout<<"input string to a.txt"<<endl;
    cin.getline(data,100);
    outfile<<data<<endl;

    Books bk1;
    strcpy( bk1.title, "C++ 教程");
    cout << "第一本书标题 : " << bk1.title <<endl;

    cout << "Hello World!" << endl;
    int a = 0;
    int b = 20;
    try {
        xxq_space::swap(a,b);
    } catch(const char* msg) {
       cerr<<msg<<endl;
    }

    cout <<a<<endl;

    xxq_space::printTest();

    return 0;
}

项目:https://github.com/xuexiangqian12345/testCPlusLanguage.git

C语言工程管理

编写符合GUN惯例的MakeFile
shell编程
CMake
gdb调试
gtest单元测试

git使用
线上有道笔记
bat批处理

算法与数据结构

排序算法
冒泡排序、选择排序、插入排序、快速排序、希尔排序、归并排序、堆排序、计数排序、桶排序(线下笔记)

顺序表、链表、栈、队列
二叉树

C语言高级编程

多线程

创建子线程循环打印并且sleep(2)
主线程也循环打印并且sleep(1)
并且等待子线程完成任务
参考:https://blog.csdn.net/modiziri/article/details/41960179?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522159110763019195162538982%2522%252C%2522scm%2522%253A%252220140713.130102334…%2522%257D&request_id=159110763019195162538982&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2blogsobaiduend~default-2-41960179.pc_v2_rank_blog_default&utm_term=linux%E5%A4%9A%E7%BA%BF%E7%A8%8B%E7%BC%96%E7%A8%8B%E5%AE%9E%E4%BE%8B
linux下编译命令:g++ -std=c++11 -o main main.cpp -lpthread
下面代码window可运行 Qt工程中添加CONFIG += c++11

#include <iostream>
#include <unistd.h>
#include <pthread.h>
using namespace std;

void *thread(void *ptr)
{
    for(int i = 0;i < 3;i++) {
        sleep(1);
        cout << "This is a pthread." << endl;
    }
    return 0;
}

int main() {
    pthread_t id;
    int ret = pthread_create(&id, NULL, thread, NULL);
    if(ret) {
        cout << "Create pthread error!" << endl;
        return 1;
    }
    for(int i = 0;i < 3;i++) {
        cout <<  "This is the main process." << endl;
        sleep(1);
    }
    pthread_join(id, NULL);
    return 0;
}

项目:https://github.com/xuexiangqian12345/testCPlusLanguage.git

网络

数据库

mysql见菜鸟和线下笔记

图形图像

Linux下的C开发(见博客)

软件架构设计

设计模式(参考android中的设计模式)

计算机基础

操作系统
计算机组成原理
计算机网络
编译原理
计算机英语

开源软件

来源:csdn Git sourceforge gitee
问题:stackoverflow
openexif
redis
zlib
boost
gtest
qt
reflect

开发笔记

开发交流

qq:649234558

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值