J
John Williams
I need a way to determine how many characters are in a command line
argument. Basically the code snippet looks like
int main(int argc, char *argv[])
{
openfiles(argv[1], argv[2], &infile, &outfile);
cipher(&infile, &outfile, argv[3]);
return 0;
}
void cipher(fstream *infile, fstream *outfile, char key[])
{
plain text in
bring in the key
cipher text out
}
Right now the entire program works, because I have it set up to only
accept 8 character keys. I'd like to set it up so that it can determine
at runtime how many characters the key is. Since the key is accepted at
the command line I can't figure out how it's done since sizeof(argv[3])
will always return the sizeof a pointer to a char (4) and
sizeof(*argv[3]) seems to always return the size of a single char (1).
argument. Basically the code snippet looks like
int main(int argc, char *argv[])
{
openfiles(argv[1], argv[2], &infile, &outfile);
cipher(&infile, &outfile, argv[3]);
return 0;
}
void cipher(fstream *infile, fstream *outfile, char key[])
{
plain text in
bring in the key
cipher text out
}
Right now the entire program works, because I have it set up to only
accept 8 character keys. I'd like to set it up so that it can determine
at runtime how many characters the key is. Since the key is accepted at
the command line I can't figure out how it's done since sizeof(argv[3])
will always return the sizeof a pointer to a char (4) and
sizeof(*argv[3]) seems to always return the size of a single char (1).