I'm trying to find the number of newline characters in a simple string but keep getting 0 for the variable numline.
What can I do to find the two little newline commands?
Here is my code:
(as you can see I'm a beginner)
//stringstep
#include <iostream>
using namespace std;
int endline=0 ;
int numline=0 ;
int counter=0 ;
// this is my string sample
char harb2[ ]=" Find the end" "\n" "Then you will see" "\n" ;
int lsizharb=strlen(harb2) ;
int main( )
{
for (counter=0;counter<=lsizharb; counter++)
if(harb2[counter]==0) // this seems to get end of string marker
endline++;
if(harb2[counter]=='\n') // this ends up with 0 !
numline++;
cout <<numline << endl;
return 0;
}