【问题标题】:C string prototype declaration [duplicate]C字符串原型声明[重复]
【发布时间】:2021-12-12 19:13:44
【问题描述】:
# how to declare string in prototype?
void myfunction(???,int);

# function that uses a string, call it like this...
void myfunction("hello world", int i)
{
   code ...
}

我尝试在原型中声明字符串,但未成功 charchar[*]

仅供参考,我尝试原型化的实际程序代码是

SDL_Window* win* = SDL_CreateWindow("Hello World!", 100, 100, 620, 387, SDL_WINDOW_SHOWN);

【问题讨论】:

  • const char* 是您将使用的类型声明。
  • 来自the docs: SDL_Window * SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags);
  • void myfunction(const char* str, int whatever);
  • @JHBonarius 不过,从 1990 年代初期开始,这似乎是一个非常过时的学习资源。不建议初学者随便看网上乱七八糟的教程。

标签: c prototype


【解决方案1】:

请看代码

#include <stdio.h>

// how to declare string in prototype?
void myfunction(char[],int);

// function that uses a string, call it like this...
void myfunction(char msg[], int i) {
   printf("%s %d", msg, i);
}

int main() {

    char msg[]= "Hello World";
    int val = 123;
    myfunction(msg, val);
    
    return 0;
    
}

【讨论】:

  • 一些解释可能会有所帮助...
  • 谢谢,复制的 cmets
猜你喜欢
  • 2014-01-03
  • 2014-06-03
  • 1970-01-01
  • 2023-03-12
  • 2018-02-20
  • 2012-02-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多