有沒有辦法讓一個函數存儲一個字符串,然後在int main()中調用該函數來在屏幕上顯示它?我一直在尋找很多,並沒有找到一個明確的例子。這是我的代碼。我希望能夠在不使用if語句的情況下調用它C程序。調用一個打印字符串的函數
#include <stdio.h>
/* function declaration */
int StrPrint(char *str);
/* main() function */
int main()
{
char str[] = "The string i am returning n";
int (*ptr)(char *str);
ptr = StrPrint;
if (!(*ptr)(str))
printf("Done!\n");
return 0;
}
/* function definition */
int StrPrint(char *str)
{
printf("%s\n", str);
return 0;
}
是的,有。你試過什麼了? – 2014-12-05 04:35:28
我已經做了一個函數來存儲一個字符串,但是當我在主函數中調用它時,它會給我一個錯誤。 – FlipFlopSquid 2014-12-05 04:40:08
編輯您的文章幷包含您的代碼。 – 2014-12-05 04:40:20