That's the worst thing to be learned. Especially if you are a learner you should learn writing code without goto. Learning bad things is never a good idea.
Maybe the below functions might give you some help. They make use of
- strchr to find a character
- memmove to remove the character by copying everything after the character
/*
Remove all characters in src specified by c
In:
src: text to process
ch: character to remove
*/
void RemoveChar(char *src, char ch)
{
// find the character
char *ptr = strchr(src, ch);
// if found
while (ptr != NULL)
{
// remove
memmove(ptr, ptr + 1, strlen(ptr));
// find next character
ptr = strchr(src, ch);
}
}
/*
Remove character at position pos from src
In:
src: text to process
pos: position to remove from
*/
void RemoveCharAt(char *src, size_t pos)
{
// safety check
if (pos > strlen(src))
{
return;
}
// remove character at position pos
memmove(&src[pos], &src[pos + 1], strlen(&src[pos]) + 1);
}
You can use it as demonstrated in setup() below
char userName[16] = "Hello World !!";
char userData[16];
void setup()
{
Serial.begin(115200);
Serial.println(userName);
// if you don't want to modify the original userName, first copy to e.g. userData
strcpy(userData, userName);
// and use userData in below instead of userName
// remove spaces
RemoveChar(userName, ' ');
Serial.println(userName);
// remove first character
RemoveCharAt(userName, 0);
Serial.println(userName);
// remove 5th character
RemoveCharAt(userName, 4);
Serial.println(userName);
// remove last character
RemoveCharAt(userName, strlen(userName) - 1);
Serial.println(userName);
}
void loop()
{
}
[edit]
Important; I missed that your arrays don't use a terminator.
[/edit]
Some notes on your existing code
- Some functions do not always return a value although they should; e.g. DataLocation().
- In some functions, variables are not initialised. TP is not initialised, HU is not initialised.
- I think that I saw somewhere a return statement and on the next line another statement (which would never be executed); can't find it back

@TomGeorge
Hey I was wondering if you can help me with my project too, I know it's completely out of nowhere and unrelated to this topic but I need to finish this because I want to learn something new, I have this project that I am still working on, which is basically a serial monitor based kind of graphic User interface and a application, yeah I used ASCIIs to create graphics lol, anyway there this function in my code which isn't working fine, it's called remove char of class profile what it does is that it removes white spaces from the string problem is that somehow it is adding white spaces at the end of the string even though it's not adding between. I tried searching on internet for anatomy of such functions, but unfortunately found nothing, I don't want to inbuilt remove char function because I wanna learn that stuff. I will really appreciate any help
Cyphonvoid,
Thanks
here's my code
Here's how you enter the application
#include "PROFILE.h"
Profile USER;
byte DisplayCount;
void setup(){
Serial.begin(115200);
}
void loop(){
byte Var = Serial.read();
if(Var == 'o'){
USERProfile();
}
if(Var == 'h'){
USER.Display(6);
}
delay(20);
}
void wait(){
while(Serial.available() == 0){
}
}
void filter(){
for(byte i = 1; Serial.available() >= i;){
Serial.read();
delay(7);
}
}
And here's the class which contains functions which data sorting and manipulation and lot of stuff
class Profile {
public:
char INFO[15];
char Username[16] = {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' };
char Password[16] = {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' };
byte LIMIT;
byte storeIndex = 0;
byte storeIndex2 = 0;
byte i = 0;
byte N = 0;
byte P = 1;
byte S = 0;
byte SerialSTRlen;
String Name;
String Pass;
String NameInfo[6] = {"0", "0", "0", "0", "0"};
String PassInfo[6] = {"0", "0", "0", "0", "0"};
String USERDATA[2];
byte c = 0;
String Ques[5];
void filter(){
//Filters out the serial buffer
for(int i = 1; Serial.available() >= i; ){
Serial.read();
delay(30);
}
}
int wait(){ //Hangs the control loop at specific point in code
while(Serial.available() == 0){
delay(4);
}
}
String StoreInfo(byte g, char a){
char Temp;
delay(30);
storeIndex = Serial.available();
SerialSTRlen = storeIndex;
for(int i = 0; i < storeIndex; i++){
Temp = Serial.read();
if(a == 'U'){
Username[i] = Temp;
}
if(a == 'P'){
Password[i] = Temp;
}
if(i == 0){
USERDATA[g] = Temp;
}
if(i > 0){
USERDATA[g] = USERDATA[g] + Temp;
}
delay(5);
}
storeIndex = 0;
return USERDATA[g];
}
int REGISTER(){
if(true){
NameInfo[i] = USERDATA[0];
PassInfo[i] = USERDATA[1];
if(i < 6){
if((USERDATA[0] == NameInfo[i]) && (USERDATA[1] == PassInfo[i])){
i++;
return true;
}
else{
return false;
}
}
}
}
int VERIFY(){
byte P = 0;
for(byte j = 0; j <= 6; j++){
if((USERDATA[0] == NameInfo[j]) and (USERDATA[1] == PassInfo[j])){
P = 1;
return true;
}
}
if(P < 1){
return false;
}
}
byte VERIFY2(byte r){
if(r == 1){ //Directly calling this function VERIFY() ISN'T WORKING SO, Had to put it in another function inside this class
VERIFY(); // And then call this function to call the first function
}
}
int Display(int a){
for(int i = 0; i < a; i++){
Serial.print(" [[Account Name]] " + NameInfo[i] + " ");
Serial.println( " [[Account Password]] " + PassInfo[i]);
}
}
byte SystemScan(){
bool RG = REGISTER();
bool VR = VERIFY();
if((RG == false) || (VR == false)){
if(RG == false){
Serial.println();
Serial.println(" ïžĨïžēïžēïžŊïžē ïž(ððšðīðĩðĶðŪ ððģðģð°ðģ) ð
ðððð ðĄðððĄððð ðđððððð! â â");
}
if(VR == false){
Serial.println();
Serial.println(" ïžĨïžēïžēïžŊïžē ïž(ððšðīðĩðĶðŪ ððģðģð°ðģ) ðķðððððĄ ððððððĶ! â â");
}
}
if((RG == false) && (VR == false)){
Serial.println(" ");
Serial.println(" ð ðĶððððēðš ððŪðķðđððŋðē ð !!");
}
else{
Serial.println();
Serial.println(" ");
Serial.println(" â ððĢð ðĢðĪðŽðĢ ðð§ð§ðĪð§ ðĪðððŠð§ðð â ");
}
}
byte ForgotInfo(byte a){
for(int i = 0; i < a; i++){
if(USERDATA[0] == NameInfo[i]){
return 'n';
}
if(USERDATA[1] == PassInfo[i]){
return 'p';
}
}
}
byte SETQues(byte IN, String ANS){
Ques[IN] = ANS;
}
byte DataLocation(String Name, String Pass, byte a, bool Setcodepcs){ //Gives the index number of the data stored in array
byte TP;
if(Setcodepcs == true){
for(byte t = 0; t < 6; t++){
if((Name == NameInfo[t]) and (Pass == PassInfo[t])){
return t;
TP++;
}
}
if(TP == 0){
return 100;
}
}
if(Setcodepcs == false){
for(byte g = 0; g < 6; g++){
if((Name == NameInfo[g]) or (Pass == PassInfo[g])){
TP++;
return g;
}
}
if(TP == 0){
return 100;
}
}
}
byte StringLength(bool y){
byte strcount = 0;
if(y == true){
for(byte i = 0; i == i; i++){ //This code right here gives the number of characters in a string value, it doesn't include the strings with spaces eg ' '.
if(Username[i] != ' '){
strcount++;
if(Username[i+1] == ' '){
for(byte w = i+1; w < 16; w++){ //This for loop removes character spaces from getting counted
if(Username[w] != ' '){
strcount++;
}
}
return strcount;
}
}
}
}
if(y == false){
for(byte i = 0; i == i; i++){
if(Password[i] != ' '){
strcount++;
if(Password[i+1] == ' '){
for(byte d = i + 1; d < 16; d++){
if(Password[d] != ' '){
strcount++;
}
}
return strcount;
}
}
}
}
}
byte ParseData2(byte STR){ //Capital letter detection.
byte Inc = 0;
for(byte i = 0; i <= STR; i++){
if((Password[i] >= 'A') && (Password[i] <= 'Z')){
for(byte h = 0; h <= 15; h++){
Password[h] = ' ';
Username[h] = ' ';
}
Inc++;
return true;
}
}
if(Inc == 0){
for(byte k = 0; k <= 15; k++){
Password[k] = ' ';
}
return false;
}
}
byte RemoveChar(byte a){
byte STR2;
for(byte i = 0; i < 15; i++){
if(Username[i] == ' '){
for(byte u = i; u < 15; u++){
if(Username[u] != ' '){
STR2 = u;
for(byte g = i; g < 15; g++){
Username[g] = Username[STR2];
Username[STR2] = ' ';
STR2++;
if(Username[STR2] == ' '){
goto PT2;
}
}
}
}
}
PT2:;
}
}
byte VERIFY3(byte x ){
byte HU;
for(byte i = 0; i < 6; i++){
if((USERDATA[x] == NameInfo[i]) or (USERDATA[x] == PassInfo[i])){
HU++;
return true;
}
}
if(HU == 0){
return false;
}
}
};
And Finally this is the function where everything happens, This function Userprofile calls other three functions named "register, Login, and Settings" and these function use the functions from the class as tools for data manipulation, storage, sorting, verification, parsing etc. THE REMOVE CHAR function is the problem it doesn't work that well.
int USERProfile(){ //This is the home page it's a individual functions which uses PROFILE.h class's functions as building blocks of UI
if(DisplayCount > 0){
for(byte m = 0; m <= 5; m++){
Serial.println();
}
}
DisplayCount++;
Serial.println(F(" `7MMF' `7MMF' "));
Serial.println(F(" MM MM "));
Serial.println(F(" MM MM ,pW'Wq.`7MMpMMMb.pMMMb. .gP'Ya `7MMpdMAo. ,6'Yb. .P`Ybmmm .gP'Ya "));
Serial.println(F(" MMmmmmmmMM 6W' `Wb MM MM MM ,M' Yb MM `Wb 8) MM :MI I8 ,M' Yb "));
Serial.println(F(" MM MM 8M M8 MM MM MM 8M'''''' MM M8 ,pm9MM WmmmP' 8M'''''' "));
Serial.println(F(" MM MM YA. ,A9 MM MM MM YM. , MM ,AP 8M MM 8M YM. , "));
Serial.println(F(" .JMML. .JMML.`Ybmd9'.JMML JMML JMML.`Mbmmd' MMbmmd' `Moo9^Yo.YMMMMMb `Mbmmd'"));
Serial.println(F(" MM 6' dP "));
Serial.println(F(" .JMML. Ybmmmd' "));
Serial.println();
Serial.println();
Serial.println(F(" ðĄðĪð ðð(i) ðūð§ðððĐð ðžðððĪðŠðĢðĐ(c) ðððĐðĐððĢððĻ(s)"));
Serial.println();
Serial.println();
Serial.println(F(" New User? -> SĖēiĖēgĖēnĖē UĖēPĖē "));
Serial.println();
Serial.println(F(" Already have an account? -> lĖēoĖēgĖē IĖēNĖē "));
Serial.println();
Serial.println(F(" [[INTRODUCTION]] "));
Serial.println();
Serial.println(F(" WELCOME, This is a LED based Snake game. You can explore several game modes and can enjoy"));
Serial.println(F(" the game with your friends and family through our Multiplayer game features "));
Serial.println(F(" We've been implementing tons of game features of make the gameplay enjoyable"));
Serial.println(F(" Since, this game is still under development phase, only registered users can play the game "));
Serial.println(F(" PLEASE Sign UP if you're new user "));
USER.filter();
wait();
char Select = Serial.read();
if(Select == 'i'){
LOGIN(0, 0);
}
if(Select == 'c'){
REGISTRATION();
}
if(Select == 's'){
Settings();
}
}
byte LOGIN(byte X, byte T){ //This function takes input from the user and verifies if the info is correct
byte pass;
byte LostInfo;
bool alpha = true;
R_EnterP:
Serial.println();
Serial.println();
Serial.println(" EĖēnĖētĖēeĖērĖē UĖēsĖēeĖērĖēnĖēaĖēmĖēeĖē ");
USER.filter();
wait();
delay(20);
USER.StoreInfo(USER.N, 'U');
USER.filter();
if(alpha == false){
goto VRFY;
}
R_EnterN:
Serial.println();
Serial.println(" EĖēnĖētĖēeĖērĖē PĖēaĖēsĖēsĖēwĖēoĖērĖēdĖē ");
Serial.println();
wait();
delay(20);
USER.StoreInfo(USER.P, 'U');
VRFY:
delay(20);
bool B = USER.VERIFY();
while(true) {
if(B == true){
Serial.println(" Verifying Account.......");
delay(800);
Serial.print(" STATUS :");
Serial.println(" ððķðĪðĪðĶðīðīð§ðķð â ");
Serial.println();
Serial.println(" ðð§ððĻðĻ(ðĨ) ððĪð§ ðžðððĪðŠðĢðĐ ðŋððĐðððĄðĻ ðĪð§ ðĨð§ððĻðĻ ððĢðŪ ð ððŪ ðĐðĪ ðððð");
USER.filter();
wait();
char UD = Serial.read();
if(UD == 'p'){
Serial.println();
Serial.print(" ððŽððŦð§ððĶð ðð ðððŽðŽð°ðĻðŦð ");
Serial.println();
Serial.print(" ðð°ð° ððēððŪðķðđð - " + USER.NameInfo[USER.i - 1] + " " + USER.PassInfo[USER.i - 1]);
Serial.println();
Serial.println();
Serial.println();
Serial.println();
Serial.println();
}
else if(UD != 'p'){
Serial.println();
Serial.println();
Serial.println(" ðŠ ððąðĒððð ðŠ ");
}
}
if(B == false){
Serial.print(" Verifying Account.......");
Serial.println(" ðŧðð ðĻðððððð ð
ððð ððð ðððððð ");
delay(800);
Serial.print(" STATUS :");
Serial.print(" ððŊðīðķðĪðĪðĶðīðīð§ðķð â ");
char FI = USER.ForgotInfo(6);
if(FI == 'n'){ //These are the options when user has forgotten details and needs to recover
Serial.println(" Re-Enter(r) or Forgot Password(f) ? ");
}
else if(FI == 'p'){
Serial.println(" Re-Enter(r) or Forgot Username(f) ? ");
}
OPT1:
filter();
wait();
char RA = Serial.read();
if(RA == 'f'){
if((FI == 'n') || (FI == 'p')){
RECOVERY(6);
break;
}
}
if(RA == 'r'){
if(FI == 'n'){
goto R_EnterN;
}
else if(FI == 'p'){
alpha = false;
goto R_EnterP;
}
}
else{
goto OPT1;
}
}
break;
}
}
byte REGISTRATION(){ //This is the registration page which registers the new user
String TMPdata = " ";
while(true){
filter();
//Serial.println(" ___ _ ______ _ _ _ _ ");
//Serial.println(" / _ \ | | | ___ \ (_) | | | | (_) ");
//Serial.println(" / /_\ \ ___ ___ ___ _ _ _ __ | |_ | |_/ /___ __ _ _ ___| |_ _ __ __ _| |_ _ ___ _ __ ");
//Serial.println(" | _ |/ __/ __/ _ \| | | | '_ \| __| | // _ \/ _` | / __| __| '__/ _` | __| |/ _ \| '_ \ ");
//Serial.println(" | | | | (_| (_| (_) | |_| | | | | |_ | |\ \ __/ (_| | \__ \ |_| | | (_| | |_| | (_) | | | |");
//Serial.println(" \_| |_/\___\___\___/ \__,_|_| |_|\__| \_| \_\___|\__, |_|___/\__|_| \__,_|\__|_|\___/|_| |_|");
//Serial.println(" __/ | ");
//Serial.println(" |___/ ");
Serial.println(" ð·ððððð ððððð ððð ððððððððð ðððððððð
ð
ðððððð CANCEL(c)");
Serial.println();
Serial.println();
Serial.println(" NOTE:- Username and Password must not exceed more than 12 characters");
USN:
Serial.println();
Serial.print(" `-:ðððððððð:-` " + TMPdata);
filter();
wait();
delay(30);
USER.StoreInfo(0, 'U');
filter();
byte str1 = USER.StringLength(true);
bool userName = USER.ParseData2(str1);
USER.RemoveChar(0);
for(byte w = 0; w <= (USER.SerialSTRlen-2); w++){ //Here the variable SerialSTRlen is storing the value of the length of a string, which has already been counted and
if(w == 0){ // stored in this variable, we're using this value here to not assign anything extra in array causing any problems or bugs
USER.USERDATA[0] = USER.Username[w];
// [[!!SENSITIVE PART OF CODE!!]]
}
if(w > 0){
USER.USERDATA[0] = USER.USERDATA[0] + USER.Username[w];
}
}
Serial.print(USER.USERDATA[0]);
Serial.println(USER.SerialSTRlen); //Extra space character causing the problem
byte Cnt = 0;
PASS:;
Serial.print(" `-:ðððððððð:-` Must include atleast one Upper case letter in your password");
Serial.println();
Serial.println();
filter();
wait();
USER.StoreInfo(1, 'P');
byte str2 = USER.StringLength(false);
bool UpperCase2 = USER.ParseData2(str2);
//***************************************************************************************************//
if( ((str1 > 12) || (str2 > 12)) or ((str1 > 12) && (str2 > 12))){
for(byte q = 0; q <= 3; q++){
Serial.println();
}
if((str1 > 12) and (str2 < 12)){
char Input;
Serial.println();
Serial.print(F(" `-:ðððððððð:-` Username length has exceeded 12 character limit "));
Serial.println();
Serial.println(F(" Cancel Registration(c) OR Proceed(p) to change Username "));
POINT3:
filter();
wait();
delay(20);
Input = Serial.read();
if(Input == 'p'){
goto USN;
}
if(Input == 'c'){
goto END;
}
else{
goto POINT3;
}
}
else if((str2 > 12) and (str1 < 12)){
char Input;
Serial.println();
Serial.print(F(" `-:ðððððððð:-` Password has exceeded 12 character limit!"));
Serial.println();
Serial.println(F(" Cancel Registration(c) OR Proceed(p) to change PASSWORD "));
POINT1:
filter();
wait();
Input = Serial.read();
if(Input == 'p'){
goto PASS;
}
if(Input == 'c'){
goto END;
}
else{
goto POINT1;
}
}
else{
Serial.println();
Serial.println();
Serial.println(F(" ââ Either Username or Password has exceeded 12 Character LIMIT ââ!! "));
Serial.println();
Serial.println(F(" Cancel Registration(c) OR Proceed(p) to change details "));
POINT2:
filter();
wait();
char Input = Serial.read();
if(Input == 'p'){
goto USN;
}
if(Input == 'c'){
goto END;
}
else{
goto POINT2;
}
}
}
//*************************************************************************************************//
if(UpperCase2 == false){
Serial.print(F(" !!INCLUDE ATLEAST ONE UPPERCASE LETTER!! "));
Serial.println();
Serial.println();
Serial.println();
Cnt++;
goto PASS;
}
if(Cnt > 0){
Serial.println(" Details have been verified ");
}
bool CHK = USER.VERIFY();
if(CHK == true){
Serial.println(F(" Account Already exists !!"));
break;
}
USER.REGISTER();
bool k = USER.VERIFY();
if(k == true){
Serial.print(" ðð°ð° ððēððŪðķðđð - ");
Serial.print(" " + USER.NameInfo[USER.i-1]);
Serial.println(" " + USER.PassInfo[USER.i-1]);
}
if(k == false){ //This code here checks if anything went wrong while registering if something does it initializes diagnostics to inspect
Serial.println(" "); // Problem, it checks several code blocks and function and returns values representing functioning of code.
Serial.print(" ðð§ðĒððĒððĨðĒðģðĒð§ð ððĒðð ð§ðĻðŽððĒððŽ...");
delay(1000);
Serial.print("..");
delay(700);
Serial.print(".....");
delay(750);
Serial.println("..");
USER.SystemScan();
}
break;
}
filter();
END:
;
}
byte RECOVERY(byte a){
Serial.println();
Serial.println(" [[ ACCOUNT RECOVERY ]]) ");
Serial.println();
Serial.println();
Serial.println(" PĖērĖēoĖēvĖēiĖēdĖēeĖē uĖēsĖē aĖēnĖēyĖē AĖēcĖēcĖē IĖēnĖēfĖēoĖē tĖēhĖēaĖētĖē yĖēoĖēuĖē aĖērĖēeĖē aĖēbĖēlĖēeĖē tĖēoĖē rĖēeĖēmĖēeĖēmĖēbĖēeĖērĖē :- ");
Serial.println();
Serial.println(" ððžðŋðīðžð ðĢðŪððððžðŋðą(ð―) â ððžðŋðīðžð ðĻððēðŋðŧðŪðšðē(ðŧ) â ");
OPT3:
filter();
wait();
char INFO = Serial.read();
if(INFO == 'p'){
Serial.println();
Serial.println(" ððŧððēðŋ ðĻððēðŋðŧðŪðšðē ");
Serial.println();
filter();
wait();
delay(20);
USER.StoreInfo(0, 'U');
delay(10);
byte indx = USER.DataLocation(USER.USERDATA[0], USER.USERDATA[0], 6, false);
Serial.println(indx);
Serial.println(" Enter the Security code ");
filter();
wait();
String D = USER.StoreInfo(0, 'U');
byte rand = 0;
for(byte i = 0; i < 6; i++){
if(D == USER.Ques[i]){
j:
Serial.println(" Enter new password");
filter();
wait();
delay(20);
String Tem = USER.StoreInfo(1, 'P');
USER.PassInfo[indx] = Tem;
byte st = USER.StringLength(false);
bool GH = USER.ParseData2(st);
if(((GH == false) || (st > 12))){
if((GH == false) && (st < 12)){
Serial.println();
Serial.println();
Serial.println(" Must include atleast one Upper case letter ");
goto j;
}
if((GH == true) && (st > 12)){
Serial.println();
Serial.println();
Serial.println(" Your PASSWORD length has exceeded the 12 Character LIMIT ");
goto j;
}
else{
Serial.println();
Serial.println(F(" Your either password doesn't fullfill the criterion "));
goto j;
}
}
USER.Display(6);
rand++;
}
}
if(rand == 0){
Serial.println(F(" Security question does not exists "));
}
}
else if(INFO == 'n'){
ENTPASS:
Serial.println();
Serial.println();
Serial.println(" Enter Password ");
filter();
wait();
delay(20);
String Response1 = USER.StoreInfo(1, 'P');
String BufferResp1 = Response1;
byte locate = USER.DataLocation(USER.USERDATA[0], USER.USERDATA[1], 6, false);
byte Free = 0;
for(byte u = 0; u < 6; u++){
if(Response1 == USER.PassInfo[u]){
Free++;
Serial.println();
Serial.println(" Enter the Security CODE/Question, if not so then please consider doing it for your recovery ");
Serial.println();
filter();
wait();
delay(20);
Response1 = USER.StoreInfo(1, 'P');
for(byte w = 0; w < 6; w++){
if(Response1 == USER.Ques[w]){
Free++;
User:
Serial.println();
Serial.println(" Enter NEW Username ");
Serial.println();
filter();
wait();
delay(20);
////////////////////////////////////////////////////////////////////
USER.NameInfo[locate] = USER.StoreInfo(0, 'U'); /* CODE FOR STORING THE NEW USERNAME, OR REPLACING THE OLD ONE */
//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
bool Recheck = USER.VERIFY();
byte WE = USER.StringLength(true);
bool UPLWcase = USER.ParseData2(WE);
if(Recheck == true){
Serial.println();
Serial.println(" This password has already been Selected, take the other name or press exit(e) to leave ");
filter();
wait();
delay(20);
if(Serial.read() == 'e'){
Serial.println(" EXITED");
break;
}
}
if((WE > 12)){
Serial.println();
Serial.println(" Can't you just type NoRmaLly?? you just literally mistyped something wrong, DUMB! ");
Serial.println(" Now press(p) to enter again or just press exit(e) to get out ");
Range:
filter();
wait();
char AGR = Serial.read();
if(AGR == 'p'){
goto User;
}
else if(AGR == 'e'){
break;
}
else{
goto Range;
}
}
Serial.println();
Serial.println(" PRESS(p) for Account details or PRESS(e) to Exit ");
Serial.println();
filter();
wait();
double TemVar = Serial.read();
if(TemVar == 'p'){
Serial.print(" Username"); Serial.println(" Password ");
Serial.println(" ACC details :- " + USER.NameInfo[locate] + " " + USER.PassInfo[locate]);
goto END;
}
else if(TemVar == 'e'){
Serial.println(" [EXITED] ");
break;
}
}
}
}
}
switch(Free){
case 1:
Serial.println();
Serial.println(" security code doesn't exist ");
break;
case 0:
Serial.println();
Serial.println(" Password is not correct !");
goto ENTPASS;
break;
}
}
else{
goto OPT3;
}
END:;
}
void Settings(){
Serial.println();
Serial.println(" [[ Settings ]]");
Serial.println();
Serial.println();
Serial.println(" Enter USERNAME");
filter();
wait();
delay(20);
USER.StoreInfo(0, 'U');
Serial.println(" Enter Password ");
filter();
wait();
delay(20);
USER.StoreInfo(1, 'U');
bool IN = USER.VERIFY();
byte inNO = USER.DataLocation(USER.USERDATA[0], USER.USERDATA[1], 6, true );
if(IN == true){
Serial.println(" Choose a security code ");
filter();
wait();
String tempData = USER.StoreInfo(0, 'U');
USER.SETQues(inNO, tempData);
Serial.println(USER.Ques[inNO]);
Serial.println(inNO);
}
else if(IN == false){
Serial.println(" The details submitted are wrong or the account does not exist");
}
}
first when you enter the application there are some options like create account, log in, settings, that's where those functions from class are used.
Split from an unrelated topic
TOPIC SPLIT
PLEASE DO NOT HIJACK / NECRO POST !
Could you take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.
You seem to be starting with 16 spaces in a 16-character array:
char Username[16] = {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' };
What do you want to be in that array after you call "RemoveChar()"?
aka "return;"
Except, you promised your function would return a byte, but it doesn't.
Ever
Don't worry. It's probably the same byte it takes as an argument and never uses. ![]()
And I think we now have a cross post with Arduino Memory FULL, I don't know why ![]()
I think so too
@cyphonvoid
Topics merged
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.
Continued cross posting could result in a time out from the forum.
Could you also take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.
Unless you are very careful STR2 will exceed 15 at some point.
Do you have some particular objection to null-terminating the text? That would make things a bit easier.
OOPS, I overlooked that in reply #42 ![]()
@david_2018 Yes I had some objections when using null terminating characters, I was using functions like wait() and filter() which basically filter out serial buffer to store new values and wait to hang the control at one place in code the problem was that those functions will not work if I use null terminating characters, this was when I was just learning basic stuff. I came across a video where a youtuber kind of made an interface of couple lines where you can select which led to blink, and I was blown away that you could do that, so I thought I can use this to make an entire Proper Interface, so I started working on it. Next I will take null characters in consideration. And I apologize for very delayed responses since I had robotics tournament and I was busy hours and hours.
I am not sure which function you're talking about, I think this statement you highlighted is from one of my kind of like individual Interface modules like setting(), recovery(), login() etc these are just supposed to be like separate processes or code pieces.
Hey, Thanks for suggesting but for the current project I have fixed all of my bugs except I haven't still got rid of goto statements, I was thinking maybe I will make another project without goto statements.
After removing the character like spaces I want the same username in that array but without spaces. I was able to figure out where I was making mistakes, basically I was shifting values in the array and assigning spaces at the end of string as I shift characters to left and then I had a spaces replaced with next characters to them and those characters got replaced with spaces, that is why it was assigning spaces at the end of string, I did some adjustments in code where after removing spaces the final assignment of array is handled by another function, and it also helps me count length of string easily
here's my final code
byte REGISTRATION(){ //This is the registration page which registers the new user
String TMPdata = " ";
while(true){
filter();
//Serial.println(" ___ _ ______ _ _ _ _ ");
//Serial.println(" / _ \ | | | ___ \ (_) | | | | (_) ");
//Serial.println(" / /_\ \ ___ ___ ___ _ _ _ __ | |_ | |_/ /___ __ _ _ ___| |_ _ __ __ _| |_ _ ___ _ __ ");
//Serial.println(" | _ |/ __/ __/ _ \| | | | '_ \| __| | // _ \/ _` | / __| __| '__/ _` | __| |/ _ \| '_ \ ");
//Serial.println(" | | | | (_| (_| (_) | |_| | | | | |_ | |\ \ __/ (_| | \__ \ |_| | | (_| | |_| | (_) | | | |");
//Serial.println(" \_| |_/\___\___\___/ \__,_|_| |_|\__| \_| \_\___|\__, |_|___/\__|_| \__,_|\__|_|\___/|_| |_|");
//Serial.println(" __/ | ");
//Serial.println(" |___/ ");
Serial.println(F(" ð·ððððð ððððð ððð ððððððððð ðððððððð
ð
ðððððð CANCEL(c)"));
Serial.println();
Serial.println();
Serial.println(" NOTE:- Username and Password must not exceed more than 12 characters");
USN:
Serial.println();
Serial.print(" `-:ðððððððð:-` " + TMPdata);
filter();
wait();
delay(30);
USER.StoreInfo(0, 'U');
filter();
USER.RemoveChar(0); //I used this first
byte str1 = USER.StringLength(true); //Then get string length
bool userName = USER.ParseData2(str1); //then check correct alpha bets
USER.Assign(str1, 0); //Finaly character assignment for use
Serial.print(USER.USERDATA[0]); //Here the variable SerialSTRlen is storing the value of the length of a string, which has already been counted and
Serial.println(USER.SerialSTRlen); // stored in this variable, we're using this value here to not assign anything extra in array causing any problems or bugs
// [[!!SENSITIVE PART OF CODE!!]]
//Extra space character causing the problem
byte Cnt = 0;
PASS:;
Serial.print(F(" `-:ðððððððð:-` Must include atleast one Upper case letter in your password"));
Serial.println();
Serial.println();
filter();
wait();
USER.StoreInfo(1, 'P');
byte str2 = USER.StringLength(false);
bool UpperCase2 = USER.ParseData2(str2);
//***************************************************************************************************//
if( ((str1 > 12) || (str2 > 12)) or ((str1 > 12) && (str2 > 12))){
for(byte q = 0; q <= 3; q++){
Serial.println();
}
if((str1 > 12) and (str2 < 12)){
char Input;
Serial.println();
Serial.print(F(" `-:ðððððððð:-` Username length has exceeded 12 character limit "));
Serial.println();
Serial.println(F(" Cancel Registration(c) OR Proceed(p) to change Username "));
POINT3:
filter();
wait();
delay(20);
Input = Serial.read();
if(Input == 'p'){
goto USN;
}
if(Input == 'c'){
goto END;
}
else{
goto POINT3;
}
}
else if((str2 > 12) and (str1 < 12)){
char Input;
Serial.println();
Serial.print(F(" `-:ðððððððð:-` Password has exceeded 12 character limit!"));
Serial.println();
Serial.println(F(" Cancel Registration(c) OR Proceed(p) to change PASSWORD "));
POINT1:
filter();
wait();
Input = Serial.read();
if(Input == 'p'){
goto PASS;
}
if(Input == 'c'){
goto END;
}
else{
goto POINT1;
}
}
else{
Serial.println();
Serial.println();
Serial.println(F(" ââ Either Username or Password has exceeded 12 Character LIMIT ââ!! "));
Serial.println();
Serial.println(F(" Cancel Registration(c) OR Proceed(p) to change details "));
POINT2:
filter();
wait();
char Input = Serial.read();
if(Input == 'p'){
goto USN;
}
if(Input == 'c'){
goto END;
}
else{
goto POINT2;
}
}
}
//*************************************************************************************************//
if(UpperCase2 == false){
Serial.print(F(" !!INCLUDE ATLEAST ONE UPPERCASE LETTER!! "));
Serial.println();
Serial.println();
Serial.println();
Cnt++;
goto PASS;
}
if(Cnt > 0){
Serial.println(F(" Details have been verified "));
}
bool CHK = USER.VERIFY();
if(CHK == true){
Serial.println(F(" Account Already exists !!"));
break;
}
USER.REGISTER();
bool k = USER.VERIFY();
if(k == true){
Serial.print(" ðð°ð° ððēððŪðķðđð - ");
Serial.print(" " + USER.NameInfo[USER.i-1]);
Serial.println(" " + USER.PassInfo[USER.i-1]);
}
if(k == false){ //This code here checks if anything went wrong while registering if something does it initializes diagnostics to inspect
Serial.println(" "); // Problem, it checks several code blocks and function and returns values representing functioning of code.
Serial.print(" ðð§ðĒððĒððĨðĒðģðĒð§ð ððĒðð ð§ðĻðŽððĒððŽ...");
delay(1000);
Serial.print("..");
delay(700);
Serial.print(".....");
delay(750);
Serial.println("..");
USER.SystemScan();
}
break;
}
filter();
END: ;
}
Yes I am starting with 16 spaces because that's something I thought User wouldn't choose to have in their password or username and I can use it to determine whether or not the strings end, it would've been easier with null characters but it was too late to change anything for I was bit lazy, I think it's better to start over again new to implement those changes
Oh okay lol yeah I have an argument that I think I don't use it, my idea was to make a function that can remove any character but then it was complicated for me so I thought to just go with this, then I forgot to remove that argument.
I agree some of my functions don't return values, but I am not sure if DataLocation is one them, The reason I didn't initialize variables like TP and HU is because default value is 0 so why initialize them if that's what I want.
But If you have some reason behind your suggestion of initializing, then I would definitely like to learn about it and understand what it is.
Because automatic (i.e. stack) variables are NOT initialized. You get what was already existing in that memory location.