Apr 29, 2011 at 11:59pm UTC
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 May 2, 2011 at 10:47am UTC