C语言 尝试从我知道存在且良好但无法打开的文件中读取



当我尝试打开文件"canbus.txt.txt"时,它返回一条错误消息,反复读出"错误:没有错误"。我找不到这个问题的来源。我的文件在主项目目录中,名称和扩展名都正确。

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int i;
char value;
char test[60];
char *line;
int num = 0;
int address[25];
int values[25];
void ms_delay (int N)
{
    T1CON = 0x08030;
    int delay = N * 62.5;   // 1 Milisecond => .001 / (256 * (1/16,000,000)) = 62.5
    TMR1 = 0;
    while (TMR1 < delay);
}
int main (void)
{
    PIN_MANAGER_Initialize();
    UART1_Initialize();
    ECAN1_Initialize();
    ECAN1_ReceiveEnable();
    INTERRUPT_Initialize();
    FILE *fp;
    char* filename = "canbus.txt.txt";
    fp = fopen(filename, "r");
    if(fp == NULL){
        perror("Error");
        exit(EXIT_FAILURE);
    }
    while(fgets(line, sizeof(line), fp)){
        fscanf(fp, "%lf %lf", &address[num], &values[num]);
        sprintf(test, "Value = %lf  Other = %lf", address[num], values[num]);
            int i = 0;
            while(test[i] != ''){
                    UART1_Write(test[i]);
                i++;
            }
        ++num;
    }        
    ms_delay(250);
    UART1_Write(0x0D);
    UART1_Write(0x0A);
    fclose(fp);
    return 0;
}
#include <stdio.h>
 int main()
  {
    FILE *fr;
    char c;
    fr = fopen("prog.txt", "r");
    while( c != EOF)
    {
      c = fgetc(fr); /* read from file*/
      printf("%c",c); /*  display on screen*/
    }
    fclose(fr);
    return 0;
    }

了解更多 https://www.codesdope.com/c-enjoy-with-files/

相关内容

  • 没有找到相关文章

最新更新