コード例 #1
0
ファイル: main.c プロジェクト: sceptre12/CProgrammingBtrees
/*
  Xavier Thomas
  Section U01
  I affirm that this program is entirely my own work and none of it is the work of any other person.
*/
int main(int argc, char *argv[]){
    printf("Welcome To assignment 1\n");

    int caseSensitive = 0;
    char *outputFile = NULL;
    char *inputFile = NULL;
    parseCommandLineOptions(argc,argv,&caseSensitive,&outputFile,&inputFile);

    // printf("Case '%d' , outputFile '%s' inputfile '%s'\n",caseSensitive,outputFile,inputFile);

    int readType = determineRead(inputFile);

    // printf("Read Type '%d'\n", readType);

    if(readType){
        readFile(inputFile,caseSensitive);
    }else{
        readFromInput(caseSensitive);
    }

    determineOutput(outputFile);

    printPostOrder(&root);
    printf("End Of Assingment\n");
    return 0;
}
コード例 #2
0
int main(void)
{
    /*整型溢出举例*/
    unsigned char x = 0xff;
    printf("%d\n", ++x);

    signed char y =0x7f; //注:0xff就是-1了,因为最高位是1也就是负数了
    printf("%d\n", ++y);

    signed char m = 0x7f;
    signed char n = 0x05;
    signed char r = m * n;
    printf("%d\n", r);

    /*示例一:整型溢出导致死循环*/
    short len = 0;
    while(len< MAX_LEN) {
        len += readFromInput(fd, buf);
        buf += len;
    }

    /*示例二:整型转型时的溢出*/
    int copy_something(char *buf, int len)
    {
        #define MAX_LEN 256
        char mybuf[MAX_LEN];

        if(len > MAX_LEN){ // <---- [1]
            return -1;
        }

        return memcpy(mybuf, buf, len);
    }