String Character Changing
#1

Alright, I'm having an issue with string character replacement:

Код:
if(!strcmp(input[i],"A") && input[i] != '\0'){input[i] = 'C'; continue;}
Picture 26 of these lines total, and they're in a for loop. Each line represents a letter of the alphabet, and a letter to replace it with.

Issue: When I enter a string such as "STRING", only the last letter is changed, instead of all of the characters.
Reply
#2

When you use input[i] it returns the entire string from that point onwards. For example:
pawn Код:
new input[6] = "hello";
printf("%s", input[1]);
//prints: ello
The proper way to compare a single character would be:
pawn Код:
if(input[i] == 'A')
Note: single quotes.
But you may want to look at an implementation of rot13 or similar; 26 similar lines does not seem efficient at all.
Reply
#3

Quote:
Originally Posted by Vince
Посмотреть сообщение
When you use input[i] it returns the entire string from that point onwards. For example:
pawn Код:
new input[6] = "hello";
printf("%s", input[1]);
//prints: ello
The proper way to compare a single character would be:
pawn Код:
if(input[i] == 'A')
Note: single quotes.
But you may want to look at an implementation of rot13 or similar; 26 similar lines does not seem efficient at all.
While it might not be efficient, It's easy to read (but not easy on the eyes). Thanks for that correction, and I did some research on rot13. The difference is, you could change the character set in those 26 lines, with rot13, it's all the same key (it seems, from a short research period).

EDIT: I wrote this script as a sort of proof of concept to myself and to a friend, I might turn this into a stock to use for a wider range of jumbling
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)