This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes C / C++ and the fly likes convert char pointer to int gives segmentation fault Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Languages » C / C++
Bookmark "convert char pointer to int gives segmentation fault" Watch "convert char pointer to int gives segmentation fault" New topic
Author

convert char pointer to int gives segmentation fault

Grace Russo
Ranch Hand

Joined: Nov 08, 2010
Posts: 64

input is something like "word-2"
How do I convert from char pointer to int ?

Grace Russo
Ranch Hand

Joined: Nov 08, 2010
Posts: 64
made some modifications
inside the if statement:



Why ?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

"50" is the ASCII value of the numeral "2".

ASCII


[Jess in Action][AskingGoodQuestions]
Grace Russo
Ranch Hand

Joined: Nov 08, 2010
Posts: 64
Ernest Friedman-Hill wrote:"50" is the ASCII value of the numeral "2".

ASCII


Doh !!
In assigning

version = *tmp_result;

how do I make the int version be equal to "2", and not to the ascii value of the numeral ?
Grace Russo
Ranch Hand

Joined: Nov 08, 2010
Posts: 64


I tried atoi like in



but got the warning: passing arg 1 of `atoi' makes pointer from integer without a cast
Grace Russo
Ranch Hand

Joined: Nov 08, 2010
Posts: 64



got it:




tmp_result is a pointer
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: convert char pointer to int gives segmentation fault
 
Similar Threads
64-bit JNI C++ to JAVA invocation multiple threads classloader problem
C/C++: How to get the fractional part of a double
C2143 error and I can't find it
String Tokenizer
Help with my first Objective-C class