Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends

What i am doing
I am reading certain text through INI file and drawing that through ::Drawtext(..) over the windows but it contain a new line character (\n).

I do have an ini file
C++
[TEST_CODE]
TEST_KEY = Check \n data


Problem
When i read through ini file using function
C++
::GetPrivateProfileString
i get the string in form of Check \n data
C++
\n
not being treated as new line character.
When i display/drawtext data over the window i get the say display \n character displayed over the window.
NOTE: this issue is not related to DrawText(..) i am sure about it :)

So please tell em what should i do to resolve this issue.
Any idea please.
Thanks in advance

Keep smiling its free :)
Posted

The newline character is not interpreted by the DrawText()[^] function, as all text positioning must be handled by the controlling program. You need to split the line(s) yourself and then display them in the correct positions.
 
Share this answer
 
Comments
kaushik4study 20-Oct-12 9:15am    
@richard i have tested the same code with the string text which is working fine. But it is not working with the ini file reading as i have mentioned earlier.
Richard MacCutchan 20-Oct-12 9:53am    
Then I can only assume that the characters you have in the ini file do not match the characters you are searching for. You need to be much more specific about your problem, we cannot guess what your data contains.
When reading with GetPrivateProfileString, or any other file read function "\n" is considered as two characters, and it is not a newline special character. You can solve this by replacing "\\n" with "\n".
And it will convert "\n" as a special character.
C++
CString cs( cBuffer ); // cBuffer is the srting from GetPrivateProfileString.
cs.Replace( "\\n", "\n" );
 
Share this answer
 
v2
Comments
kaushik4study 20-Oct-12 8:28am    
@santosh Thanks for reply but that basically changes my project requirement:
Basically it is the user who will edit manually ini file. So if user will edit ini file he is not considered to write new line character as \\n or there are other charaters may be required in future eg (\r and others). Although you solution is somehow can solve the problem but i hope you can understand my concern.


Thanks for answering.
Chuck O'Toole 20-Oct-12 22:51pm    
You are totally confusing the C language syntax for "escaped strings". The code shown uses "\\" to generate exactly one character that is a backslash. Therefore C code is replacing the two character string "\n" with the single character "newline". The user would not enter the three keystroke sequence "\\n" only the two character sequence "\n". If you are going to be coding in C/C++ then you need to study more about C character string language notations.
Santhosh G_ 20-Oct-12 8:38am    
If possible, replace all combinations of before display.
Other option is to implement drawing of the string based on the special characters.
kaushik4study 20-Oct-12 8:41am    
Other option is to implement drawing of the string based on the special characters.?????
Santhosh G_ 20-Oct-12 8:47am    
You have to parse the string to find "\n" and draw it in new line. If "\t" is in ini file, then you have to put 4 space for that and like that. Like that you have to consider all special characters for drawing.
Sorry for misunderstanding.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900