无法找出如何隔离数字并替换它

问题描述 投票:0回答:1

我所做的是使用我提取的第一组代码提取数据并将其放入新文件,因此仅是值

这是我的第一组代码的输入文件:

original input

这是第二组代码的输入文件,这是我的主要问题:

second set of input code

然后在第二组代码中是读取新文件的位置,因此它将使用fgetc输出数字,现在我如何使用此简单的公式呢?具体来说,公式会将任何10的值变成0的值我尝试过,并且由于fgetc是unsigned char,所以我尝试在if语句中使用10的二进制数]

到目前为止,这是我的代码:

#include<stdio.h> 

int main() 
{ 
    FILE* ptr = fopen("Data.txt","r"); 
    if (ptr==NULL) 
    { 
        printf("no such file."); 
        return 0; 
    } 

    FILE*fp = fopen("/data flow/NEWdata.txt", "w+");

        int x;
  int count=0;
    char buf[100];
    fscanf(ptr,"%*s %*s %*s %*s %*s %*s %*s %s ",buf); //skip first line and stuff before first value(column names)
    while (fscanf(ptr,"%*s %*s %*s %*s %s  ",buf)==1) 
    {

        fprintf(fp, "%s\n",buf);
    }
    fclose(fp); 
    return 0; 
} 

第二组代码

#include <stdio.h>
#include <stdlib.h>

int main () {
   FILE *fp;
   char str[100];

   /* opening file for reading */
   fp = fopen("NEWdata.txt" , "r");
   if(fp == NULL) {
      perror("Error opening file");
      return(-1);
   }
   int i;
   while( fgets (str, 100, fp)!=NULL ) {
      /* writing content to stdout */
      sscanf (str,%u,i);
    printf(%u,i);

   }
   fclose(fp);

   return(0);
}

我应该是命令行enter image description here

错误即时通讯低于enter image description here

if (10.0 <= measure && measure < 11.0)
            fprintf (ofp, "%.3f\n", measure - 10.);
        else
            fprintf (ofp, "%.3f\n", measure);

我所做的是使用第一组代码提取了数据并将其放入新文件中,因此仅是值。这是第一组代码的输入文件:原始输入这是我的输入...

c scanf readfile data-manipulation fgetc
1个回答
0
投票

如果我理解正确,并且您想从Data.txt中读取值,并且如果Measurement的值是10,则要将其设置为0。如我的评论中所述,您的Measurement值是浮点

© www.soinside.com 2019 - 2024. All rights reserved.