Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help! How Can I... 1

Status
Not open for further replies.

bnhshallow

Programmer
Dec 14, 2001
12
US
Hi Everyone.
What I am trying to do in my program is read data from a file and make the program trigger events from the data in the file. The problem I am having is that the fgets() reads a line from the file, but also reads the '\n' or "Enter Mark" at the end of the string. If Possible, How can i get rid of the \n ant the end of the string, or make it so the
if(text=="ENDREADSESSION(Quit)") will see the \n as a charecter


///************Sample Code From File***********///
FILE *txtfile;
char text[1000];
txtfile=fopen(m_sResults,"r");
///////////DIV

if (txtfile)
{
while (!feof(txtfile))
{
fgets(text,300,txtfile); //////Reads Unwanted Newline
if(text=="ENDREADSESSION(Quit)")/////Does not trigger because of newline
{
MessageBox("ENDREADSESSION(Quit)--Quiting WinFunc® .","File Command--#106");
}


There are no errors in the code that MFC is telling me about.


Thanks in advance.BNH
 
#include <iostream>
#include <string>

int main()
{
char sTemp[100];
strcpy( sTemp,&quot;This string\nhas a newline.&quot; );

std::cout << &quot;With the newline sTemp = &quot; << sTemp;
*( strrchr( sTemp,'\n' ) )='\0';

std::cout << std::endl
<< std::endl
<< &quot;Minus the newline sTemp = &quot;
<< sTemp
<< std::endl;

return 0;
} Mike L.G.
mlg400@blazemail.com
 
Thanks, I had to change a few things and it worked perfect.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top