atoi problem

This is a discussion on atoi problem within the C++ Programming forums, part of the General Programming Boards category; Hi guys, im having a segmentation fault in my program coming from an atoi. Code: #include <iostream> using namespace std; ...

  1. #1
    Registered User cdonlan's Avatar
    Join Date
    Sep 2004
    Posts
    49

    atoi problem

    Hi guys, im having a segmentation fault in my program coming from an atoi.
    Code:
    #include <iostream>
    using namespace std;
    
    
    int main(int argc, char *argv[]) {
      int num;
    
      num = atoi(argv[1]);
    
    
    
      return 0;
    }
    Im using g++ if it makes a difference...

    Thanks
    Chris

  2. #2
    Registered User
    Join Date
    Mar 2004
    Posts
    536
    Quote Originally Posted by cdonlan
    Hi guys, im having a segmentation fault in my program coming from an atoi.

    Thanks
    Chris
    Are you giving it an argument?


    Code:
      if (argc > 1) {
        cout << "You entered " << argv[1] << endl;
        num = atoi(argv[1]);
        cout << "num = " << num << endl;
      }
      else {
        cout << "No argument given" << endl;
      }
    Regards,

    Dave
    Last edited by Dave Evans; 01-20-2005 at 03:03 PM.

  3. #3
    Registered User cdonlan's Avatar
    Join Date
    Sep 2004
    Posts
    49
    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  2. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  3. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  4. Problem with atoi()?
    By ruthgrin in forum C++ Programming
    Replies: 4
    Last Post: 03-19-2006, 11:25 AM
  5. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 05:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21