日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

c打印行号和函数_使用C中的函数名称,行号从任何函数打印错误消息

發(fā)布時(shí)間:2023/12/1 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c打印行号和函数_使用C中的函数名称,行号从任何函数打印错误消息 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

c打印行號(hào)和函數(shù)

Sometimes, it is necessary to print some message on logic failure or anytime with the function name and line number, so that program can be debugged and fixed the issue.

有時(shí),有必要在邏輯故障時(shí)或在任何時(shí)候使用功能名稱和行??號(hào)打印一些消息,以便可以調(diào)試程序并解決問題。

Prerequisite:

先決條件:

  • __LINE__: To print current line number

    __LINE__ :打印當(dāng)前行號(hào)

  • __func__: To print the name of the current function

    __func__:打印當(dāng)前函數(shù)的名稱

Program:

程序:

#include <stdio.h>float devide(int a, int b) {float result;if(b!=0){result = (float)a/(float)b;}else{result=0;printf("Error at line %d in function \"%s\"\n",((__LINE__)-3),__func__);//ERROR at 3 lines above: ((__LINE__)-3)}return result; }int main() {printf("%f\n",devide(10,3));printf("%f\n",devide(10,0)); return 0; }

Output

輸出量

3.333333 Error at line 9 in function "devide" 0.000000

翻譯自: https://www.includehelp.com/c-programs/print-error-message-from-any-function-with-function-name-line-number-in-c.aspx

c打印行號(hào)和函數(shù)

總結(jié)

以上是生活随笔為你收集整理的c打印行号和函数_使用C中的函数名称,行号从任何函数打印错误消息的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。