简体   繁体   English

警告:格式的参数过多-fprintf

[英]warning: too many arguments for format - fprintf

    pthread_t      writeToFile = pthread_self ();
    unsigned short iterate;

    for (iterate = 0; iterate < 10000; iterate++)
    {
        fprintf (fp, " %d ",  iterate,     4);
        fprintf (fp, " %lu ", writeToFile, sizeof (pthread_t));
        fprintf (fp, "\n",    writeToFile, 1);
    }

In main () fp = fopen ("xyz", "w"); 在main()中fp = fopen ("xyz", "w");

Warning: warning: too many arguments for format 警告: warning: too many arguments for format

From here: http://www.cplusplus.com/reference/clibrary/cstdio/fprintf/ 从这里: http : //www.cplusplus.com/reference/clibrary/cstdio/fprintf/

What's wrong in my code? 我的代码有什么问题?

gcc version 4.5.0

Let's take your first fprintf : " %d " . 让我们来看你的第一个fprintf" %d " it expects one argument (an int), but you give it two - iterate and 4. 它需要一个参数(一个int),但你给它两个 - 迭代和4。

It seems like you are adding the size of the data, but you shouldn't. 似乎您正在添加数据的大小,但您不应该这样做。 It should probably be: 它可能应该是:

fprintf (fp, " %d ",  iterate);

In the other two sentences, it's not even clear what do you want to put in the file. 在另外两个句子中,甚至不清楚您要在文件中添加什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM