[Bug c++/26451] New: I get segmentation fault when executing this input/output program

didier2309 at yahoo dot fr gcc-bugzilla@gcc.gnu.org
Thu Feb 23 22:31:00 GMT 2006


I get segmentation fault when executing this input/output program:

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <iostream>
#include <cstdlib>
#include <string.h>

using namespace std;

int main(int argc, char *argv[])
{
   int num, rest, len, result;
   int control= 0;
   char *str;
   bool flag = true;
   int multi10 = 1;
   if(argc == 2){
     len = strlen(argv[1]);
   } 
   for(int i = 0; i == len-1 || isdigit(argv[1][i]) ; i++){
        flag = false;
   }
   if(argc != 2 || flag){
       cout << "To many or not enough parameters! Enter a number:";
       cin >> num;
       while(!isdigit(num)){
           cout << "\nEnter a number:";
           cin >> num;
       }
   } 
   else{
       num = atoi(argv[1]);
   }    
   if(num > 9){
     result = num;
   while(result > 9){

     result = result/10;
     multi10 = multi10 *10;
   }
   do{
      str[control] = result;
      rest = num - multi10 * result;
      result = rest; 
      while(result > 9){
          result = result/10;
          multi10 = multi10 * 10; 
      }
      control++; 
    }while(result > 0);
      cout << str;
      return EXIT_SUCCESS;
    }
}


-- 
           Summary: I get segmentation fault when executing this
                    input/output program
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: blocker
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: didier2309 at yahoo dot fr


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26451



More information about the Gcc-bugs mailing list