• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

convert char pointer to int gives segmentation fault

 
Grace Green
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

 
Grace Green
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
made some modifications
inside the if statement:



Why ?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"50" is the ASCII value of the numeral "2".

ASCII
 
Grace Green
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 Green
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I tried atoi like in



but got the warning: passing arg 1 of `atoi' makes pointer from integer without a cast
 
Grace Green
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



got it:




tmp_result is a pointer
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic