+ 1
Help in C
I need to convert from string to int (but not to print). int main(int argc, string arvc[]) So I used: int key = atoi(arvc[1]) But I’m having a pointer problem I can’t understand...
8 Réponses
+ 2
Badglass im doing substitution problem, i found when entering on command line in ide.cs50, it counts the -0 as argv[1] and then your text as argv[2]. Also, on the Ascii charts a direct cast from the character 2 to an int so (int)'2' produces the decimal number 50, char '0' <- zero is equal to 48, so if you wanted to convert from a character digit to a usable integer you would need to do this
int KEY = (int)char - 48;
idk if any of this will help, without being able to test whats going on with your code im kind of limited.
also, it could be treating the value you get from argv[1] as an array itself, which would give you a pointer to int conversion error if you tried to cast it, in which case you might be able to do this
command line: ./Caesar -0 5
program:
int KEY = (int)argv[1][0] - 48;
+ 2
This will help you.
https://www.google.com/amp/s/www.geeksforgeeks.org/command-line-arguments-in-c-cpp/amp/
Happy coding <^_^>
+ 1
Charitra Agarwal but my main problem is on convert...
+ 1
Badglass
Have a deep look on that website, you'll get where you were making mistake.
+ 1
Robert Atkins yess.. I’m stuck in caesar’s problem
+ 1
Robert Atkins thank youu, it helped me a lot...
0
Yo, you taking cs50 on edx? working on the cryptography part?
0
Badglass anytime, it was my pleasure.