I would like to know if there is some kind of formula that will tell the script how many varialbes the user will need.
Ex: "Input amount of strings you will use"
cin>> 8
And then the user would input 8 strings. And then the 8 strings would be used in the scripts
In the overall prespective I'm trying to input strings of hexadecimal ranges like 112a-112f or just strings of hexadecimal numbers like a3b1 and then if its a range like "112a-112f" I would break that string into two strings like "112a" and "112f" then I would sstream those two strings into integers and would print all the hexadecimal number in between.
Problem:
well as you can see I been having to insert a variable for each single string hex number or for each string hex range. I need to be able to input 200 ranges or so and I need to find a way that the user can tell the script how many ranges(strings) he will input and then have those strings be converted into integers and so on like i have been able to do(see code).
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <ctime>
#include <iomanip>
using namespace std;
int main(){
cout<<"Please Enter a Maximum of 30 Values\n\n";
cout<<"If you have less than 30 values just apply a zero after you last number with a space between them before pressing enter\n\n";
cout<<"When done placing values press Enter\n\n";
time_t curr=time(0);
ofstream res("result.txt", ios::app);
res<< "Time Processed: " << ctime(&curr) <<"\n";
int zzz; //exits
char hex1[10];char hex2[10];char hex3[10];char hex4[10];char hex5[10];char hex6[10];char hex7[10];
char hex8[10];char hex9[10];char hex10[10];char hex11[10];char hex12[10];char hex13[10];char hex14[10];
char hex15[10];char hex16[10];char hex17[10];char hex18[10];char hex19[10];char hex20[10];char hex21[10];
char hex22[10];char hex23[10];char hex24[10];char hex25[10];char hex26[10];char hex27[10];char hex28[10];
char hex29[10];char hex30[10]; //30 values
////////////////////111111111
cin>>hex1;
if(strlen(hex1)==1){ // if one of the inputs of the string was zero
goto stop;
}
else{
if(strlen(hex1)< 9){ //strlen returns the length of the char array 1234-1234
cout<<hex1<<"\n";
res<<hex1<<"\n";
}
else{
char *aa = strtok(hex1,"-"); //places in a group (group f) the characters from begging up to the hypen
char *bb = strtok(NULL, "\0"); //places in a group (group b) the character from after the hypen to the end of the string
int aaa;
int bbb;
stringstream con1(aa);
stringstream con2(bb);
con1>>hex>>aaa;
con2>>hex>>bbb;
while(aaa<=bbb){
cout << hex << setw(4) << setfill('0') << aaa << endl; // prints zeros
res << hex << setw(4) << setfill('0') << aaa << endl; // prints zeros
aaa++;
}
}
}
stop:
cout << "\n\nYour luns have been proccessed\n\n";
cout << "Please enter q and find resluts on file result.txt\n\n";
cin>>zzz;
} return 0;
}
thanks in advance,
Izzy
This post has been edited by izzyprime86: 26 June 2008 - 11:32 AM

New Topic/Question
Reply




MultiQuote




|