• 《C和指针》学习笔记[第二章 基本概念]


    2.7问题

    1.无法通过编译,适配最后第一个*/,后面那个无法适配

    2.优点的话,管理比较方便,各个函数冲突少。缺点,任何修改需要重新编译整个源文件,费时间。

    3.在每个?前面添加\转移字符

    4. \40=空格 \100=@

    \x100报错,hex escape sequence out of range

    \0123 分别为\012 与3

    \x0123 报错 \x后面的数字,mac的gcc编译器会全部适配,不是只有3个字符

    5. 报错,因为注释为一个空格,两个变量初始化中间少了逗号

    6.没啥错误,虽然更关键字看过去有点像,但并不一致,关键字都是小写的,stop不是关键字

    7.错,还是排班好比较好,因为是给人看的

    8.两个对少了while的右括号[看答案的],第二个好,因为第二个有缩进

    9.编译gcc -c 链接 gcc

    10最后添加 -lparse

    11 list.c改了 gcc -c list.c 

    list.h改了 gcc -c list.c table.c main.c

    table.h改了 gcc -c table.c main.c

    2.8编程练习

    main.c

    #include <stdio.h>
    #include <stdlib.h>
    
    #include "increment.h"
    #include "negate.h"
    
    #define NUM 3
    int
    main(void)
    {
    
        int num_array[NUM] = {10, 0, -10};
        for (int i=0; i < NUM; i++) {
            printf("increment num = %d, negate num = %d\n", increment(num_array[i]), negate(num_array[i]));
        }
        
        return EXIT_SUCCESS;
    }

    increment.h

    #ifndef increment_h
    #define increment_h
    
    #include <stdio.h>
    
    int increment(int num);
    
    #endif /* increment_h */

    increment.c

    #include "increment.h"
    
    int
    increment(int num)
    {
        return num + 1;
    }

    negate.h

    #ifndef negate_h
    #define negate_h
    
    #include <stdio.h>
    
    int negate(int num);
    #endif /* negate_h */

    negate.c

    #include "negate.h"
    
    int
    negate(int num)
    {
        return -num;
    }

    2.[抄了答案]逻辑简单

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    #include "t_c.h"
    
    int main(void)
    {
        
        int ch;
        int braces = 0;
        
        while ((ch = getchar() ) != EOF) {
            if (ch == '{') {
                braces++;
            }
            else if ( ch == '}' ){
                if ( braces == 0 ) {
                    printf("Extra closing brace!\n");
                }
                else{
                    braces--;
                }
            }
        }
        
        if (braces != 0 ) {
            printf("%d unmatched opening brace(s)!\n", braces);
        }
        
        return EXIT_SUCCESS;
    }
  • 相关阅读:
    Ehcache缓存回收策略
    [字符编码]Invalid byte 1 of 1byte UTF8
    JavaScript 单例模式
    Java程序员应该了解的10个设计原则
    医疗基本知识之医嘱篇(二)医嘱组成及规范
    VC++ (三)虚函数与重载
    VC++ (一)类的强制转换
    还是一个医学伦理问题,医疗费用高怪谁?
    电子病历开发经验共享 —— 2009年一时兴起写在某个论坛上的,转抄留恋。
    VC++ (二)类的访问级别
  • 原文地址:https://www.cnblogs.com/sidianok/p/16327563.html
Copyright © 2020-2023  润新知