For my summer project I built a cheesy little encryption engine, I wanted to have a feature where the user could enter a string/char series and it would encrypt it right in the terminal but for some reason the program (I think its scanf) is only printing out the first word. It could be the way I determine the end of users input but I believe the problem is scanf and not my code (although I read this and it makes me question myself). Here is the code that is relevent:
printf("would you like to [e]ncrypt or [d]ecrypt, or type a word to encrypt\n");
char q[50];
for(int s = 0; s<50; s++){ //initialize string to '0'
q[s] = '0';
}
scanf("%s \n", q); //reads input from user
for(int s = 0; s<50; s++){ //for loop to read every char and encrypt it
if(q[s] == '0'){ //'0' determines the end of line
break;
}else{
union shifter sh = { 0 }; //uses a union to shift the char to unreadable (relatively) char
sh.str = q[s];
sh.i += 5;
printf("%c", sh.str); //prints out chars one at a time
}
}
printf("\n"); //new line when done
inb4 you guys say that the user can't enter a 0, I know this, as a side question, could I initialize it to an unreadable char by doing say
char = 3;
and putting it as a unreadable char (end of test to be exact)
thanks for the help