1. 程式人生 > 其它 >C語言實戰基礎知識點-持續更新

C語言實戰基礎知識點-持續更新

技術標籤:Linux C語言程式設計

C語言實戰基礎知識點

  • 正常情況下C語言執行函式一定要在呼叫函式上方宣告,但是通過在上方進行function declare方法宣告,既可以在呼叫函式下方進行實現。
/* 定義 */
int Compute_string_md5(unsigned char *dest_str, unsigned int dest_len, char *md5_str);
int main(int argc, char *argv[])
{
    /* 呼叫*/
    Compute_string_md5((unsigned char *)test_str, strlen
(test_str), md5_str); printf("[string - %s] md5 value:\n", test_str); printf("%s\n", md5_str); return 0; } /* 實現 */ int Compute_string_md5(unsigned char *dest_str, unsigned int dest_len, char *md5_str) { //...省略程式碼 return 0; }
  • gcc 編譯引入了.h程式(簡易版)
gcc "引入的.h指向的c檔案路徑"
"要編譯的檔案" -o "你想要編譯的名稱"

假如檔案路徑如下

在這裡插入圖片描述

想編譯md5test.c檔案,這個檔案中引用了md5.h

#include "md5.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#define
READ_DATA_SIZE 1024
#define MD5_SIZE 16 #define MD5_STR_LEN (MD5_SIZE * 2) // function declare int Compute_string_md5(unsigned char *dest_str, unsigned int dest_len, char *md5_str); int Compute_file_md5(const char *file_path, char *md5_str); /************** main test **************/ int main(int argc, char *argv[]) { ...

那麼gcc編譯指令如下

gcc md5.c md5test.c -o run