ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

Raspberry Pi C错误:无效使用不完整类型

2019-11-19 14:50:37  阅读:302  来源: 互联网

标签:raspberry-pi c-3 linux c-4 raspbian


我正在Raspberry Pi上编写C程序.我正在使用ctime库获取当前时间和日期,使其成为文本文件的标题.例如,我当前的日期和时间是2015年10月23日的14:51.因此,文本文件的名称将为20151023_14_51.txt.这是代码:

FILE *f;
main(int argc, char *argv[]){
char dateiname[256]="";

time_t t = time(0);
struct tm * now = localtime(&t);

//Create and open file
sprintf(dateiname, "/home/raspbian/Desktop/%02d%02d%02d_%02d_%02d.txt",
            now->tm_year+1900,
            now->tm_mon+1, 
            now->tm_mday,
            now->tm_hour, 
            now->tm_min;

f = fopen(dateiname, "w");

我的问题是,当我尝试使用gcc编译程序时,出现以下性质的错误:

error: invalid use of incomplete type ‘struct main(int, char**)::tm’

error: forward decleration of ‘struct main(int, char**)::tm’

一开始我也收到此错误:

error: ‘localtime’ was not declared in this scope

我做了一些研究,发现有类似问题的人不包括sys / time.h,但我已经包括了.这是我包括的内容:

#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/time.h>

有谁知道会导致这些错误的原因,或者我是否缺少任何信息?谢谢.

解决方法:

结构tm由#include< time.h>或#include< ctime>定义.并使用std :: tm作为名称.

标签:raspberry-pi,c-3,linux,c-4,raspbian
来源: https://codeday.me/bug/20191119/2036968.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有