deleting decimals from parameters

i'm writing a piece of code for an assignment, and up to deleting commas from my parameter 1. i have sucesfully done this however if i put more than one comma in my parameter it doesn't work. if anyone could help me fix this problem it would be greatly appreciated.

regards

#include <iostream>
#include <cstdlib>
#include <stdio.h>
#include <float.h>
#include <time.h>
#include <sys/time.h>
#include <math.h>
#include <string>

using namespace std;


double num1,num2;
char* end;

int main(int argc, char *argv[])

{
if (argc == 1) //if no parameters output student number, email and name
{
cout << "S1111111B,s1111111@student.rmit.edu.au,Name_No_spaces" << endl ;
system("pause");
return(0) ;
}

if(argc==1||argc==2||argc>3)//if parameter is 1,2,>3 output "P"
{
cout<<"Parameter Error"<<endl<<"P"<<endl;
system("pause");
return(0) ;
}


int newbase = atoi (argv[2] +1);// put under comer deletion!!!!!!
cout<<endl<<newbase<<endl;



string str (argv[1]);

cout<<str<<endl;

string::size_type i=str.find(",",0);
if(i!=string::npos)
{
str.erase(i,1);
}






cout<<str<<endl;
system("pause");
return(0);
}
Last edited on
Use [code][/code] tags.
Show your problem ( give example inputs and outputs ).

argc==1||argc==2||argc>3 could be argc!=3

1
2
3
4
5
string::size_type i=str.find(",",0);
 if(i!=string::npos)
 {
 str.erase(i,1);
 }

If you want this to remove all commas, put it in a loop which reuses i
1
2
3
4
5
6
7
int i = 0;
while(true){
   i = str.find(',', i);//char instead of char* is more appropriate here.
   if(i!=string::npos)
      str.erase(i,1);
   else break;
}
Topic archived. No new replies allowed.