本文目錄一覽:
- 1、C語言中,調用 定義在調用後的函數 除了int類型的,char到底行不行,不知道不要亂說,謝
- 2、C語言為什麼可以重寫標準庫函數?
- 3、C語言調用函數問題
- 4、哪位大神能用c語言 重寫opencv 的下面6個函數??或者從源碼中整理出來,可以編譯,運行??
- 5、C語言中如何調用以前自己寫過的函數?
- 6、怎樣用C語言重寫FILE的庫函數,比如重寫fopen(),fgetc(),fclose(),fseek(),printf().
C語言中,調用 定義在調用後的函數 除了int類型的,char到底行不行,不知道不要亂說,謝
可以
char fun()
函數前面的類型 是 函數的返回值,因此一般的類型都可以,int 、char、double、int * ……都可以
C語言為什麼可以重寫標準庫函數?
這個問題是一個好問題,我之前也沒思索過或者嘗試過,
首先我們弄清楚一件事,函數聲明可以放在任何頭文件,實現可以放在任何實現該函數的源文件中,那麼就存在一個問題:
編譯時,到底優先去使用哪一個,為什麼沒有把標準庫中的函數擴展過來;在windows下標準庫被編譯成了msvcr120.dll(msvcr100.dll,這裡指release版),所以並不是擴展到代碼中,而是在調用時動態鏈接;
而題主在其中自定義文件中實現了該函數,所以編譯時找到了該函數的實現,並不會去鏈接dll(這應該是編譯器做的一些工作,確定系統的dll需要載入哪些),所以題主的程序執行時就只有一份fputc了,並不衝突。
題主可以通過快捷鍵跳轉聲明就知道了,VS下,點選fputc實現函數按F12跳轉到聲明,指向的是stdio.h,再按一次跳轉到你自己的定義了。Qt的話使用F2。
大概就是這樣子了,可追問。
C語言調用函數問題
有兩種情況,第一種:在大部分情況下都是要用到多少個參數就定義多少個.請看例子:
#include stdio.h
void weekdays(int y,int m, int d)//根據日期利用基姆拉爾森公式判定是星期幾
//看參數:一共三個,主程序中調用時,也必須用三個參數
{
int iWeek;
if(m==1||m==2) {
m+=12;
y–;
}
iWeek=(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7;//基姆拉爾森公式
switch(iWeek)//判定星期幾
{
case 0: printf(“星期一\n”); break;
case 1: printf(“星期二\n”); break;
case 2: printf(“星期三\n”); break;
case 3: printf(“星期四\n”); break;
case 4: printf(“星期五\n”); break;
case 5: printf(“星期六\n”); break;
case 6: printf(“星期日\n”); break;
}
}
int main()
{
int year=0,month=0,day=13;
printf(“請輸入日期:\n格式為:1900,1,1\n”);
scanf(“%d%d%d”,year,month,day);//輸入年,月,日
weekdays(year,month,day); //運算
return 0;
}
第二種:不定參數這個有點複雜,還是建議你自行度娘了.這種情況,函數頭定義參數個數可以比主函數實際調用時少.
哪位大神能用c語言 重寫opencv 的下面6個函數??或者從源碼中整理出來,可以編譯,運行??
去git上面看看源碼
//先說一下這個函數吧
//cvNamedWindow
CV_IMPL int cvNamedWindow(const char* name, int flags){
CV_FUNCNAME(“cvNamedWindow”);
if (!name)CV_ERROR(CV_StsNullPtr, “NULL name”);
HighguiBridge::getInstance().namedWindow(name);
return CV_OK;
}
//而它又需要HighhuiBridge這個類,它有個單例工廠方法
HighguiBridge HighguiBridge::getInstance(){
static HighguiBridge instance;
return instance;
}
//上面2個函數實際調用這2個成員函數
CvWindow* HighguiBridge::namedWindow(cv::String name) {
CvWindow* window = HighguiBridge::getInstance().findWindowByName(name.c_str());
if (!window)window = createWindow(name);
return window;
}
//創建窗口先是查找有沒有已有窗口
CvWindow* HighguiBridge::findWindowByName(cv::String name){
auto search = windowsMap-find(name);
if (search != windowsMap-end())return search-second;
return nullptr;
}
//如果沒有會用這個函數創建
CvWindow* HighguiBridge::createWindow(cv::String name){
CvWindow* window = new CvWindow(name);
windowsMap-insert(std::paircv::String, CvWindow*(name, window));
return window;
}
//創建窗口是CvWindow類
class CvWindow{
public:
CvWindow(cv::String name, int flag = CV_WINDOW_NORMAL);
~CvWindow();
/** @brief NOTE: prototype.
Should create button if there is no button with this name already.
*/
void createButton(cv::String name);
/** @brief Creates slider if there is no slider with this name already.
The function creates slider if there is no slider with this name already OR resets
provided values for the existing one.
*/
void createSlider(cv::String name, int* val, int count, CvTrackbarCallback2 on_notify, void* userdata);
/** @brief Updates window image.
@param src Image data object reference.
The function updates window image. If argument is null or image control is not found – does nothing.
*/
void updateImage(CvMat* arr);
/** @brief Returns reference to the trackbar(slider) registered within provided window.
@param name Name of the window.
The function returns reference to the trackbar(slider) registered within provided window.
Returns nullptr if trackbar with specified name is not found or window reference is nullptr.
*/
CvTrackbar* findTrackbarByName(cv::String name);
Page^ getPage();
private:
cv::String name;
// Holds image data in CV format
CvMat* imageData;
// Map of all sliders assigned to this window
std::mapcv::String, CvTrackbar** sliderMap;
// Window contents holder
Page^ page;
// Image control displayed by this window
Image^ imageControl;
// Container for sliders
Panel^ sliderPanel;
// Container for buttons
// TODO: prototype, not available via API
Panel^ buttonPanel;
// Holds image width to arrange other UI elements.
// Required since imageData-width value gets recalculated when processing
int imageWidth;
// Default markup for the container content allowing for proper components placement
static const Platform::String^ markupContent;
// Default Slider size, fallback solution for unexpected edge cases
static const double sliderDefaultWidth;
};
//CvWindwo構造函數為
CvWindow::CvWindow(cv::String name, int flags) : name(name){
this-page = (Page^)Windows::UI::Xaml::Markup::XamlReader::Load(const_castPlatform::String^(markupContent));
this-sliderMap = new std::mapcv::String, CvTrackbar*();
sliderPanel = (Panel^)page-FindName(“cvTrackbar”);
imageControl = (Image^)page-FindName(“cvImage”);
buttonPanel = (Panel^)page-FindName(“cvButton”);
// Required to adapt controls to the size of the image.
// System calculates image control width first, after that we can
// update other controls
imageControl-Loaded += ref new Windows::UI::Xaml::RoutedEventHandler(
[=](Platform::Object^ sender,
Windows::UI::Xaml::RoutedEventArgs^ e){
// Need to update sliders with appropriate width
for(auto iter=sliderMap-begin();iter!=sliderMap-end();++iter){
iter-second-getSlider()-Width = imageControl-ActualWidth;
}
// Need to update buttons with appropriate width
// TODO: implement when adding buttons
});
}
C語言中如何調用以前自己寫過的函數?
如果func是一個已經定義的函數,
可以這麼寫:func();
也可以這麼寫,如果func有返回值:a
=
func();
還可以這麼寫:
while(func()){}或
if(func()){}
怎樣用C語言重寫FILE的庫函數,比如重寫fopen(),fgetc(),fclose(),fseek(),printf().
這最好找個專業的,一般人是沒辦法寫的,一是難度大,二是這麼費事沒報酬也不好找著
找百度能找著無疑是大海撈針,最好去專業點的平台去找
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/244187.html