Tag: c

使用时间函数的链接列表打印错误

打印时间戳时程序崩溃。 我相信错误位于函数void flightRec_PrflightRecData(flightRecRead * thisFlight)中,它旨在做三件事: 声明时间结构的飞行时间,飞行时间是POSIX格式。 Localtime将POSIX时间转换为人类可读的时间。 第四个说明符使用asctime打印转换时间,该时间以Www Mmm dd hh:mm:ss yyyy格式打印。 错误是tb!= NULL并显示指定asctime的其他信息。 我做了什么来排除故障: 检查时间标题 检查指针和地址 关闭了弃用 检查格式说明符 任何帮助表示赞赏。 #include #include #include #include typedef struct flightRec_struct { // declare a struct to match the format of the binary data char FlightNum[7]; char OriginAirportCode[5]; char DestAirportCode[5]; int timestamp; } flightRec; typedef struct flightRecRead_struct { // […]

如何在c函数中动态malloc内存?

我想调用这样的函数: char* Seg(char* input, char **segs, int* tags) 实际上input是真正的输入, segs tags是返回,现在返回是错误消息。 我的程序是这样的: #include char* Seg(char* input, char **segs, int* tags) { // dynamic malloc the memory here int count = strlen(input); // this count is according to input for (int i = 0; i < count; i++) { segs[i] = "abc"; } for (int i […]

C程序中的非法初始化

我试图在Turbo C中运行此代码并在第9行进行非法初始化我做错了什么? #include #include void main() { int names[] = {23,23,34}; int *nam[] = { names, names+1 , names +2}; char *temp; clrscr(); printf(“%u” , (nam)); getch(); }

在我的C程序中使用scanf而不是fgets和fput?

#include #include int isPalindrome( char *str, int length ) { if ( length < 1 ) { return 1; /* no more chars to compare, its a palindrome */ } if ( str[0] == str[length-1] ) /* Are the two ends same? */ { return isPalindrome( str+1, length-2 ); /* continue checking */ } else […]

lua函数的警报消息

我有以下代码: lua_getglobal(L, “lgd”); lua_getfield(L, -1, “value_pos_x”); cr->value_pos_x = lua_tointeger(L, -1); if (!lua_isinteger(L, -1)) printf(“value_pos_x allows only numbers;”); lua_getfield(L, -2, “value_pos_y”); cr->value_pos_y = lua_tointeger(L, -1); if (!lua_isinteger(L, -1)) printf(“value_pos_y allows only numbers;”); lua_getfield(L, -3, “time”); cr->time = lua_tointeger(L, -1); if (!lua_isinteger(L, -1)) printf(“time allows only numbers;”); 代码完美无缺。 我想知道的问题是,是否可以只保留一条消息并且适用于每个函数,例如: lua_getglobal(L, “lgd”); lua_getfield(L, -1, “value_pos_x”); cr->value_pos_x = lua_tointeger(L, […]

编译PostgreSQL 9.6的C函数时出错

我正在升级到PostgreSQL 9.6并在尝试编译一些C代码时遇到一些错误。 gcc -c -o lib/libhaver.o src/libhaver.c -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector –param=ssp-buffer-size=4 -m64 -mtune=generic -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fPIC -D_GNU_SOURCE -I. -I/usr/pgsql-9.6/include/server -I/usr/pgsql-9.6/include/server/access -I/usr/pgsql-9.6/include/internal -I/usr/include/et -I/usr/include/libxml2 -I/usr/include 这段代码: #include “postgres.h” #include “fmgr.h” #include “catalog/pg_type.h” #include “funcapi.h” #include “utils/guc.h” #include “access/htup.h” #include “utils/array.h” #include “math.h” #ifdef NEWPOSTGRES #include […]

将双数组转换为unsigned short?

Prob = *((unsigned short*)(Prob)); Prob = (unsigned short)(Prob); 这对我不起作用。 如何正确转换?

套接字客户端使用Select

我试图实现一个客户端function,可以使用select()函数建立与多个服务器的连接。 但我不是使用select()函数的专家。 但是,我的客户端可以启用与多个服务器的连接,但它无法从这些多个服务器读取消息。 根据我的以下示例,我将我的客户端连接到两台服务器( 192.168.100.136, 192.168.100.138) 。 与这两台服务器连接后,我的客户端只从一台服务器( 192.168.100.136 )接收消息,而不是从多台服务器接收消息。 我不确定我在示例程序中使用select()函数的方式。 请更正我的示例应用程序以获得所需的o / p ..提前致谢 int main() { int port = 10001 ; char ip[][32] = {“192.168.100.136″,”192.168.100.138”}; int count = 2 ; int ret = clientSelect(ip,port,count); return 0 ; } int clientSelect(char **ipAddr ,int port , int count) { SOCKET max_sd = 0; SOCKET socketId[10] […]

动态生成变量名称

我只想知道当前编程语言中是否有任何方法可以动态生成像数组这样的变量名称,例如。 for(i=1;i<10;i++) { int a i = ; printf(“the value generated in the logic is %d”,a i); } 我知道有一个类似的方式的数组的概念,但我只是想知道这是否存在于任何编程语言中。 提前致谢….

灰度图像转换.img到.ras – 在Windows中的白色和蓝色的灰度等级?! C

我想将.img文件(512字节标题,512×512像素,每像素8位(值:0-255))转换为.ras文件。 为此,我在本文末尾得到了C代码。 我的测试图像(test.img)的输出应该是黑/白图像 – 所以只包含0或255的值。但问题是,当我在Windows中编译C代码(从底部)时,我的结果。 ras文件是白色还是亮蓝色?! 奇怪的是。 当我在Linux中编译C代码时,结果是完全黑/白?! 这怎么来的? 在两个系统中我使用了64位。 所以你可以尝试一下:1。用以下代码编译C代码:gcc -lm img2ras.c -o img2ras 2.通过控制台将.img转换为.ras:img2ras test.img test.ras 3.在gimp中观察.ras文件,XnView或PaintshopPro 你是否有任何线索如何在具有相同版本的gcc 4.8.1的不同操作系统上发生这种尴尬的结果? test.img: http : //www.file-upload.net/download-8629102/test.img.html img2ras.c /* this program accepts an input file (which comes from the image capturing board) and an output file, which must be specified on the command line. The output file […]