How to read the txt file generated under windows under linux

Recently, DSP is used to calculate the convolution algorithm. The coefficients used are the convolution coefficients generated by the PC and saved in a txt file. The TXT files generated before are all text files with tab stops, so linux can read them normally. Later, the coefficient provided by a colleague could not be read directly. If you use the while loop to read through fscanf, you feel that you have entered an endless loop. In fact, the two TXT file formats are inconsistent. You can view it by vi under your test platform. You can understand the problem. What can be read normally will be similar to 0.00003242^M. What is
abnormal is that ^@ is added in front of each number, which causes data reading errors. At this time, it needs to be in windows Save the TXT file as a txt file with tab stops (with carriage return and line feed).
By the way, a code to read the txt file is attached.

#include <stdio.h>
#include <stdlib.h>
FILE fp;
float coefs[4096];
int i = 0;
fp = fopen("fircoef.txt","r")
	if(fp == NULL){
    
    
		printf("file open error!")
		return -1;
	}
while(fscanf(fp, "%f\n", &coefs[i]) != EOF){
    
    
	i++;
}
fclose(fp);

Guess you like

Origin blog.csdn.net/coinv2014/article/details/106564625