anh5kor
22nd December 2015, 10:00
I am trying to Read a text file with the below code
QFile infile("Rte.txt");
if(infile.open(QIODevice::ReadOnly | QIODevice::Text))
{
QString line;
char line1;
QTextStream stream(&infile);
// while(!stream.atEnd())
for(int i = 0;i<20;i++)
{
line = stream.readLine();
}
infile.close();
}
The above code is reading the file Line by Line.Which is correct according to implementation but I want in some other way.
For Example
My txt file look like below pattern
FUNC(uint8, RTE_CODE) Rte_Mode_BswM_RP_GM_DcmControlDtcSetting_DcmContro lDtcSetting(void);
FUNC(uint8, RTE_CODE) Rte_Mode_BswM_RP_GM_DcmEcuReset_Dcm_EcuReset(void) ;
FUNC(Std_ReturnType, RTE_CODE) Rte_Read_BswM_RP_GM_SUM_ECUOperatingMode_RequestPo rt_SUM_ECUOperatingMode(CONSTP2VAR(UInt8, AUTOMATIC, RTE_APPL_DATA) data);
FUNC(Std_ReturnType, RTE_CODE) Rte_Read_BswM_RP_GM_SUM_RxPduMode_14_RequestPort_S UM_PduMode(CONSTP2VAR(UInt8, AUTOMATIC, RTE_APPL_DATA) data);
FUNC(Std_ReturnType, RTE_CODE) Rte_Read_BswM_RP_GM_SUM_RxPduMode_15_RequestPort_S UM_PduMode(CONSTP2VAR(UInt8, AUTOMATIC, RTE_APPL_DATA) data);
FUNC(Std_ReturnType, RTE_CODE) Rte_Read_BswM_RP_GM_SUM_RxPduMode_5_RequestPort_SU M_PduMode(CONSTP2VAR(UInt8, AUTOMATIC, RTE_APPL_DATA) data);
FUNC(Std_ReturnType, RTE_CODE) Rte_Read_BswM_RP_GM_SUM_RxPduMode_6_RequestPort_SU M_PduMode(CONSTP2VAR(UInt8, AUTOMATIC, RTE_APPL_DATA) data);
FUNC(Std_ReturnType, RTE_CODE) Rte_Read_BswM_RP_GM_SUM_RxPduMode_7_RequestPort_SU M_PduMode(CONSTP2VAR(UInt8, AUTOMATIC, RTE_APPL_DATA) data);
FUNC(Std_ReturnType, RTE_CODE) Rte_Read_BswM_RP_GM_SUM_TxPduMode_14_RequestPort_S UM_PduMode(CONSTP2VAR(UInt8, AUTOMATIC, RTE_APPL_DATA) data);
FUNC(Std_ReturnType, RTE_CODE) Rte_Read_BswM_RP_GM_SUM_TxPduMode_15_RequestPort_S UM_PduMode(CONSTP2VAR(UInt8, AUTOMATIC, RTE_APPL_DATA) data);
FUNC(Std_ReturnType, RTE_CODE) Rte_Read_BswM_RP_GM_SUM_TxPduMode_5_RequestPort_SU M_PduMode(CONSTP2VAR(UInt8, AUTOMATIC, RTE_APPL_DATA) data);
........
........
On running the above code its reads line by line
o/p:-FUNC(Std_ReturnType, RTE_CODE) Rte_Read_BswM_RP_GM_SUM_ECUOperatingMode_RequestPo rt_SUM_ECUOperatingMode(CONSTP2VAR(UInt8, AUTOMATIC, RTE_APPL_DATA) data);(for example)
but my requirement is that I should read a line in 4 parts and save the same in other file.
My output should be like below
1.o/p:-FUNC(Std_ReturnType, RTE_CODE)
2.o/p:- Rte_Read_BswM_RP_GM_SUM_ECUOperatingMode_RequestPo rt_SUM_ECUOperatingMode
3.o/p:-UInt8, AUTOMATIC, RTE_APPL_DATA
4.o/p:-data
please let me know how can I read a single line part by part.
QFile infile("Rte.txt");
if(infile.open(QIODevice::ReadOnly | QIODevice::Text))
{
QString line;
char line1;
QTextStream stream(&infile);
// while(!stream.atEnd())
for(int i = 0;i<20;i++)
{
line = stream.readLine();
}
infile.close();
}
The above code is reading the file Line by Line.Which is correct according to implementation but I want in some other way.
For Example
My txt file look like below pattern
FUNC(uint8, RTE_CODE) Rte_Mode_BswM_RP_GM_DcmControlDtcSetting_DcmContro lDtcSetting(void);
FUNC(uint8, RTE_CODE) Rte_Mode_BswM_RP_GM_DcmEcuReset_Dcm_EcuReset(void) ;
FUNC(Std_ReturnType, RTE_CODE) Rte_Read_BswM_RP_GM_SUM_ECUOperatingMode_RequestPo rt_SUM_ECUOperatingMode(CONSTP2VAR(UInt8, AUTOMATIC, RTE_APPL_DATA) data);
FUNC(Std_ReturnType, RTE_CODE) Rte_Read_BswM_RP_GM_SUM_RxPduMode_14_RequestPort_S UM_PduMode(CONSTP2VAR(UInt8, AUTOMATIC, RTE_APPL_DATA) data);
FUNC(Std_ReturnType, RTE_CODE) Rte_Read_BswM_RP_GM_SUM_RxPduMode_15_RequestPort_S UM_PduMode(CONSTP2VAR(UInt8, AUTOMATIC, RTE_APPL_DATA) data);
FUNC(Std_ReturnType, RTE_CODE) Rte_Read_BswM_RP_GM_SUM_RxPduMode_5_RequestPort_SU M_PduMode(CONSTP2VAR(UInt8, AUTOMATIC, RTE_APPL_DATA) data);
FUNC(Std_ReturnType, RTE_CODE) Rte_Read_BswM_RP_GM_SUM_RxPduMode_6_RequestPort_SU M_PduMode(CONSTP2VAR(UInt8, AUTOMATIC, RTE_APPL_DATA) data);
FUNC(Std_ReturnType, RTE_CODE) Rte_Read_BswM_RP_GM_SUM_RxPduMode_7_RequestPort_SU M_PduMode(CONSTP2VAR(UInt8, AUTOMATIC, RTE_APPL_DATA) data);
FUNC(Std_ReturnType, RTE_CODE) Rte_Read_BswM_RP_GM_SUM_TxPduMode_14_RequestPort_S UM_PduMode(CONSTP2VAR(UInt8, AUTOMATIC, RTE_APPL_DATA) data);
FUNC(Std_ReturnType, RTE_CODE) Rte_Read_BswM_RP_GM_SUM_TxPduMode_15_RequestPort_S UM_PduMode(CONSTP2VAR(UInt8, AUTOMATIC, RTE_APPL_DATA) data);
FUNC(Std_ReturnType, RTE_CODE) Rte_Read_BswM_RP_GM_SUM_TxPduMode_5_RequestPort_SU M_PduMode(CONSTP2VAR(UInt8, AUTOMATIC, RTE_APPL_DATA) data);
........
........
On running the above code its reads line by line
o/p:-FUNC(Std_ReturnType, RTE_CODE) Rte_Read_BswM_RP_GM_SUM_ECUOperatingMode_RequestPo rt_SUM_ECUOperatingMode(CONSTP2VAR(UInt8, AUTOMATIC, RTE_APPL_DATA) data);(for example)
but my requirement is that I should read a line in 4 parts and save the same in other file.
My output should be like below
1.o/p:-FUNC(Std_ReturnType, RTE_CODE)
2.o/p:- Rte_Read_BswM_RP_GM_SUM_ECUOperatingMode_RequestPo rt_SUM_ECUOperatingMode
3.o/p:-UInt8, AUTOMATIC, RTE_APPL_DATA
4.o/p:-data
please let me know how can I read a single line part by part.