New answers tagged

1

You have a structural problem. You're trying to create main(), followed by a function called is_valid_key), but you have some errors in how you did it. The main() function (yes, it's technically a function, with a special name) should end with a closing curly brace, before the start of any other functions. This code has the closing curly brace at the very ...


1

Look at this line: for (int i = 0; i < strlen(argv[i]); i++) Here you're trying to iterate over all arguments in the command line when you should iterate only over the second argument. To fix this you can create a variable: string x = argv[1]; for (int i = 0; i < strlen(x); i++) or use the address: for (int i = 0; i < strlen(&argv[1][i]); i++)...


0

I found out an approach to solve this- int main(int argc, string argv[]) { char c[strlen(argv[1])]; for (int i=0; i<strlen(argv[1]); i++ ) { c[i] = argv[1][i]; //printf("%c\n", argv[1][i]); } printf("%s\n", c); if (argc ==2 && isdigit(c[0])) { int k = c[0]; string ip = get_string("plaintext:"); } ...


1

This is a common newbie error. The problem lies here: isdigit(argv[1]) The isdigit() function and all of it's issomething() functions take a single char as input. But, argv[1] is a string, not a single char. This code is taking a string and shoving it down isdigit's throat, so it chokes and coughs up a seg fault. The code needs to check each char in argv[1]...


Top 50 recent answers are included