Tag: c

对solaris的ppoll

这段代码在Linux中编译但不在Solaris中编译,因为显然ppoll()是特定于Linux的(我在Solaris中使用GCC得到了一个未定义的符号错误)。 有任何帮助转换吗? 我不认为只使用poll()是一个好主意,但话说回来,我没有编写这段代码。 (我是用C编写命令行shell的;第一次尝试使用ncurses / C ) #include #include #include #include #include #include #include #include /** VT100 command to clear the screen. Use puts(VT100_CLEAR_SCREEN) to clear * the screen. */ #define VT100_CLEAR_SCREEN “\033[2J” /** VT100 command to reset the cursor to the top left hand corner of the * screen. */ #define VT100_CURSOR_TO_ORIGIN “\033[H” struct […]

无法在内联汇编中声明.data

你好,我有一个问题,我似乎无法声明.data。 我用我的代码尝试了各种不同的东西,它似乎总是打破这一部分 asm( “.data\n” “.file: .ascii \”/dev/mem\\000\”\n” ); 我也可以删除.data之后的任何信息,它仍会在’.data’处中断。 这是在带有内联汇编的树莓派2上完成的。如果其余的代码是相关的,请告诉我,但我很确定它不是。 谢谢你的帮助! 编辑:道歉我忘了包含错误消息 “错误:’此处’方法名称’的.size表达式不会计算为常量

作为进程子进程,如何知道哪个文件描述符是父进程

我正在尝试编写一个程序,该程序分叉并等待他的孩子完成,然后孩子在输入上做一些工作然后以与父母一样的方式分叉等等。 现在,我知道分支复制到子文件描述符数组,我应该关闭与父文件关联的那些,但我无法弄清楚哪些是父文件。 我需要给孩子这是父母的pid吗? 我一直试图在一小时的大部分时间里绕过它,我想我有一种心灵障碍,因为我无法得出结论。 TL; DR:作为子进程,我如何知道哪些文件描述符属于我的父进程?

从stdin发送任意字节到fgets

我正在使用fgets(user_input,input_len,stdin)提示用户提供的字符串。 我怎样才能将hex \ x04表示的字节发送给程序?

如何增加数组的限制?

// C Program to find average of numbers given by user #include #include #include void main() { double sum = 0; int ii = 0,c; char buf[256], *token; printf(“Enter the numbers to average on a single line, separated by space and press enter when done\n”); fgets(buf, 255, stdin); token = strtok(buf, ” “); while (token […]

fprintf没有写入文件

出于某种原因,我的fprintf语句什么也没做。 我把printf语句放在它周围,看看它是否到达它(它确实如此),但我仍然无法弄清楚为什么没有发生。 这是我的代码: #include int main(int argc, char *argv[]) { char c[8]; FILE *fp; FILE *fp2; int i=0; int count,j,temp=0; fp = fopen(argv[0],”r”); fp2 = fopen(argv[1], “w”); for(i=0; i<50;i++) { count = fread(c,1,8,fp); if(((4<i)&&(i<10))||((14<i)&&(i<20))||((24<i)&&(i<30))||((34<i)&&(i<40))||(44<i)){ continue; } else{ for(j = 0; j<count; j++){ c[j]=c[j]-'0'; c[j]=c[j] << (count – (j+1)); temp = temp | c[j]; } fprintf(fp2, […]

插入单链表C

我在C中链接列表fucntion前面的插入有问题 #define arrSIZE = 100; struct listNode { char data[arrSIZE]; struct listNode *nextPtr; }; typedef struct listNode ListNode; void insertHead(ListNode *sPtr, char value[arrSIZE]){ ListNode *newPtr = (ListNode *)malloc(sizeof(ListNode)); strncpy(newPtr->data, value, arrSIZE); if(sPtr ==NULL){ newPtr->nextPtr=NULL; sPtr = newPtr; }else{ newPtr->nextPtr=sPtr; sPtr =newPtr; } }

从文本文件中创建一个二维数组

我正在使用稀疏矩阵,并给我一个像这样的文本文件: 0 3 1.2 2 5 3.2 3 0 2.1 3 5 4.2 4 5 2.2 0 0 5.2 基本上它的工作方式是位置[0] [3]上的数字1.2和未提及的matriz的元素保持为0,所以在这种情况下它应该如下所示: 5.2 0 0 1.2 0 0 0 0 0 0 0 0 0 0 0 0 0 3.2 2.1 0 0 0 0 4.2 0 0 0 0 0 2.2

C:关于结构可见性的警告

我有一个复杂的C项目。 在文件message.h我声明了这个结构 struct message { int err; struct header { char *protocol_version; char *type; long int sequence_number; } header; struct body { int num_tag; char *tag_labels[LEN]; int num_attr_tag[LEN]; char *attr_labels[LEN][LEN]; char *attr_values[LEN][LEN]; char *attr_types[LEN][LEN]; } body; }; 在文件“castfunctions.h”中,我包含文件“message.h”,我声明函数“setClientNat” #include void *setClientNat(struct message *msg); 当我编译时,我有这个警告 castfunctions.h:warning: declaration of ‘struct message’ will not be visible outside of […]

从CSV读取数据并放入数据库

我有一个包含6列的表格,我有像这样的CSV导出,每行有6个条目 me;val1;val2;val3;val4;val5; me;val1;val2;val3;val4;val5; 我需要阅读这些条目并将其插入SQLITE3数据库中。以便解析我使用的CSV void readcsv() { FILE* stream = fopen(“input.csv”, “r”); char line[1024]; while (fgets(line, 1024, stream)) { char* tmp = strdup(line); printf(“Field 3 would be %s\n”, getcsvfield(tmp, 3)); // NOTE strtok clobbers tmp free(tmp); } } //Used for parsing CSV const char* getcsvfield(char* line, int num) { const char* tok; for (tok = […]