diff options
author | Luke Bratch <l_bratch@yahoo.co.uk> | 2010-10-30 16:59:22 +0100 |
---|---|---|
committer | Luke Bratch <l_bratch@yahoo.co.uk> | 2010-10-30 16:59:22 +0100 |
commit | 86958c4f5e1be3364955e57078fb156968f3e5ae (patch) | |
tree | a5b8ba55be2da416ed99aab05d4ae256db02097d /blasms.c | |
parent | 3f4b67c67c47fc5d02fe978ee64dbbe3f4bcb84a (diff) |
Make replacestr more generic, to allow for variable length replacements
Diffstat (limited to 'blasms.c')
-rw-r--r-- | blasms.c | 16 |
1 files changed, 8 insertions, 8 deletions
@@ -28,8 +28,8 @@ void remtrailn(char* line) { } } -/* Replace source[i] with str */ -void replacestr(char* source, int i, char* str) { +/* Replace n characters in source with str at i */ +void replacestr(char* source, int i, int n, char* str) { /* Temporary string for building */ char strtmp[1000]; @@ -37,7 +37,7 @@ void replacestr(char* source, int i, char* str) { strxfrm(source, strtmp, i); source[i] = '\0'; strcat(source, str); - strcat(source, strtmp + i + 2); + strcat(source, strtmp + i + n); } /* Converts a string to lowercase */ @@ -262,23 +262,23 @@ int main(int argc, char *argv[]) { switch (systemcmd[i+1]) { case 'N': setname(telnum); - replacestr(systemcmd, i, telnum); + replacestr(systemcmd, i, 2, telnum); break; case 'n': - replacestr(systemcmd, i, telnum); + replacestr(systemcmd, i, 2, telnum); break; case 'd': - replacestr(systemcmd, i, argv[2]); + replacestr(systemcmd, i, 2, argv[2]); break; case 's': - replacestr(systemcmd, i, sms + offset + 1); + replacestr(systemcmd, i, 2, sms + offset + 1); break; case 'P': if (!match) { settelnum(telnum, sms, &offset); match = 1; } - replacestr(systemcmd, i, telnum); + replacestr(systemcmd, i, 2, telnum); break; } } |