mercredi 2 mars 2016

How to display last N charcaters of a C string?

I'm trying to do some programming homework but I cant figure out how to display the last N characters of a C string. This is my attempt at it so far. I am also supposed to ask for the number of characters and validate it. Any help would be greatly appreciated.

 void choice_4( char str[]){


int characters;

cout<<"How many characters from the end of the string do you want to display? ";
cin>>characters;


if (str[characters]!='\0')
    cout<<str.Substring(str.length - characters,characters)

}

Aucun commentaire:

Enregistrer un commentaire