+ 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...

6th Sep 2020, 4:02 AM
Badglass
8 odpowiedzi
+ 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;
7th Sep 2020, 5:04 AM
StealthyTaco
StealthyTaco - avatar
6th Sep 2020, 4:16 AM
Charitra
Charitra - avatar
+ 1
Charitra Agarwal but my main problem is on convert...
6th Sep 2020, 4:23 AM
Badglass
+ 1
Badglass Have a deep look on that website, you'll get where you were making mistake.
6th Sep 2020, 4:28 AM
Charitra
Charitra - avatar
+ 1
Robert Atkins yess.. I’m stuck in caesar’s problem
7th Sep 2020, 3:43 AM
Badglass
+ 1
Robert Atkins thank youu, it helped me a lot...
7th Sep 2020, 5:43 AM
Badglass
0
Yo, you taking cs50 on edx? working on the cryptography part?
7th Sep 2020, 3:11 AM
StealthyTaco
StealthyTaco - avatar
0
Badglass anytime, it was my pleasure.
7th Sep 2020, 12:44 PM
StealthyTaco
StealthyTaco - avatar