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 = […]

在C中连接Postgresql

我正在尝试将在Windows上运行的C脚本连接到Postgresql数据库。 目前,我在网站上获得了这个脚本: #include #include “libpq-fe.h” #include #include int main() { PGconn *conn; PGresult *res; int rec_count; int row; int col; conn = PQconnectdb(“dbname=ljdata host=localhost user=dataman password=supersecret”); if (PQstatus(conn) == CONNECTION_BAD) { puts(“We were unable to connect to the database”); exit(0); } res = PQexec(conn, “update people set phonenumber=\’5055559999\’ where id=3”); res = PQexec(conn, “select lastname,firstname,phonenumber […]

基于ATMega8的计算器使用AVRstudi

关于计算器: 基本上这个计算器用于计算环境温度下铜和铝线的电阻,使用公式R2 = R1 *(1 + alpha(T-25)) 这里R2将是输出,R1将是用户使用4×4矩阵键盘输入的值(包括十进制值,如12.5等),T是温度传感器LM35记录的摄氏度温度。 铜的α=0.0039α,铝= 0.0042 它应该如何工作: 基本上温度将由计算器记录,该计算器将给出输入T.25℃的电阻值将由用户使用键盘输入。 现在键0-9和“。” 用于输入值。 在此之后当用户按下键盘上的“+”时,它应该实现铜的公式并在LCD上显示结果,类似地,当用户按下“ – ”时,它应该实现铝的公式。 让我们暂时保留“*”“/”和“=”按钮作为备用按钮。 进展到现在: 使用我在此附件中发送给您的代码,我能够正确地获得屏幕上的温度,我能够看到R1的值(即25°C时的电阻值)现在我无法弄清楚如何使用这些获取输出的值。 请帮我解决一下这个。 🙂 谢谢和问候,Mohit Goyal #define F_CPU 1000000UL #include #include #include #include #include “lcd.h” #include “lcd.c” #include #define KB_PORT_OUT PORTB #define KB_PORT_IN PINB void port_init(void) { DDRB = 0x0f; //Key-board port, higer nibble – input, lower […]

如何通过命令行参数传递参数将文本替换为文件的特定位置

我的目的是读取第一行中的第二个元素,并将其替换为我们作为命令行参数传递的值,并将其替换为input.txt文件中的值 输入文件:logic.txt 一个= 1234 2 = 3456 我希望在编译代码后我的文件可以像这样更改。 ./a.out 1567 目前我正在获得这样的输出 ./filelogic 1567 1567 = 1234 2 = 5678 在编译之后,应该像这样修改预期的输出文件 logic.txt 一个= 1567 2 = 5678 char buf[MAXSIZE] = {}; int num = 0; int i = 0; num = atoi(argv[1]); printf(“%d”,num); FILE *fp1; fp1 = fopen(“logic.txt”,”r”);//currently reading the file. if(fp1 != NULL) { fseek(fp1,3,0);//Need […]

我怎么能从另一个文件访问静态变量?

我怎么能从另一个文件访问静态变量? 静态变量不具有文件范围吗? bash-3.2$ ls ac bc bash-3.2$ cat ac #include static int s = 100; int fn() { /* some code */ } bash-3.2$ cat bc #include #include “ac” extern int s; int main() { printf(“s = %d \n”,s); return 0; } bash-3.2$ gcc bc bash-3.2$ a.exe s = 100

将Node插入到第一位的C编程中

这是我正在编写的程序的一个function,以便更熟悉节点。 我不确定它是否正确,但实质上是检查Node是否为Null,如果是,那么它将信息添加到代码字段并将指针设置为NULL。 否则,它会创建一个新节点并将信息插入代码字段,然后指向现有的第一个节点。 我不确定如何更改指向原始第一个节点的标头指向新节点。 代码是 typedef struct node { LibraryCode location; struct node *next; } Node; void insertFirstNode(LibraryCode code, Node **listPtr) { Node *n=*listPtr; Node *first; if(n==NULL){ n=malloc(sizeof(Node)); n->location=code; n->next=NULL; } else { Node *first; first->location=code; first->next=n; } }