我有以下
^XA^M
^SZ2^JMA^M
^MCY^PMN^M
^PW822~JSN^M
^JZY^M
^LH0,0^LRN^M
^XZ^M
^XA^M
^FO350,95^M
^BY4^BCB,220,N,N,N,A^FD12345^FS
^FT605,700^M
^A0B,40,40^M
^FB600,1,0,R,0^M
^FD12345^FS
^FT282,1160^M
^A0B,28,39^FDBilka Tilst afdelingen^FS
^FT320,1160^M
^A0B,28,39^FDAgerøvej 7^FS
^FT358,1160^M
^A0B,28,39^FDPort 39^FS
^FT396,1160^M
^A0B,28,39^FDTilst^FS
^FT434,1160^M
^A0B,28,39^FDFLD_COUNTY_FLD^FS^M
^FT472,1160^M
^A0B,28,39^FD8381^FS
^FT510,1160^M
^A0B,28,39^FDFLD_COUNTRY_FLD^FS^M
^FT548,1160^M
^A0B,28,39^FDFLD_ORDERTEL_FLD^FS^M
^FO660,100^M
^GB0,720,2^FS^M
^FO750,100^M
^GB0,720,2^FS^M
^FO660,820^M
^GB92,0,2^FS^M
^FO660,100^M
^GB92,0,2^FS^M
^FT680,810^M
^A0B,18,23^FDDELIVERY INSTRUCTIONS:^FS^M
^FT700,810^M
^A0B,18,25^FDFLD_SPECIALINST1_FLD^FS^M
^FT720,810^M
^A0B,18,25^FDFLD_SPECIALINST2_FLD^FS^M
^FT200,1160^M
^A0B,80,90^FB1160,2,0,L,0^FDFLD_SERVICETEXT_FLD^FS^M
^FT780,1160^M
^A0B,18,20^FDSender's address: ^FS^M
我正在尝试删除每行末尾的 ^M,并在 C 中包含以下内容
GLOBAL BOOLEAN CARRIER_CONSIGNOR_SIM_ReplaceZPL(CARRIER_CONSIGNOR_SIM_ORDER_TYPE* Header)
{
#define MAX_FILE_LEN 30
char filename[MAX_FILE_LEN];
snprintf(filename, MAX_FILE_LEN, "%s.zpl", Header->OrderNumber);
FILE *file;
FILE *write;
char line [256];
char linec [256];
file = fopen( filename, "r");
write = fopen( filename, "r+");
if( file != NULL )
{
while ( fgets ( line, sizeof line, file ) != NULL ) /* read a line */
{
strcpy(linec, line);
fprintf (write , linec);
}
/* Close both files */
fclose (write);
fclose (file);
printf("REPLACED LABEL in %s\n", filename);
return ( TRUE );
}
return ( FALSE );
}/*CARRIER_CONSIGNOR_SIM_ReplaceZPL*/
我已尝试对“rb+”、“r+b 和 rb 执行以下操作以写入 = fopen,但这都不会删除 ^M。解决此问题的最佳方法是什么。