Hello All,
I have been working on a problem, which requires the data to be aligned.In other words have same number of rows and columns. If this is not the case, the remaining 'spaces' are filled with an '-'.
Forexample:
File contains..
Code:
>hha
fhahahdhaa
>hhb
kskksk
>hhc
jfkdjfdk
>hhd
jjkkj
Then after processing the file contains
file 2:
Code:
>hha
fhahahdhaa
>hhb
kskksk----
>hhc
jfkdjfdk--
>hhd
jjkkj-----
I am able to solve this problem.Now the problem is that the code wont work, if the number of rows are different and I am not sure how to do it.
For example the code wont work if the file contains this:
Code:
>hha
fhahahdhaa
>hhb
kskksk
>hhc
jfkdjfdk
jiojoijo
>hhd
jjkkj
hdjhfdk
Code:
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <vector>
using namespace std;
int main(int argc, char *argv[])
{
int j,i,a,b,max;
a=0;
b=0;
max=0;
char s[255];
char t[255];
ifstream inFile;
ifstream inFile1;
// cout << "Running program " << argv[0] << endl;
if (argc != 2)
{
printf("%s [File Name]\n", argv[0]);
return -1;
}
inFile.open(argv[1]);
inFile1.open(argv[1]);
if (!inFile) {
cout << "Unable to open file";
exit(1); // terminate with error
}
while (inFile >> s) {
if(max < a){
max=a;
}
a=0;
for (i=0;i<=strlen(s)-1;i++){
if (s[i]=='a' || s[i]=='A')
a=a+1;
else if (s[i]=='-' || s[i]=='_')
a=a+1;
else if (s[i]=='b' || s[i]=='B')
a=a+1;
else if (s[i]=='c' || s[i]=='C')
a=a+1;
else if (s[i]=='d' || s[i]=='D')
a=a+1;
else if (s[i]=='e' || s[i]=='E')
a=a+1;
else if (s[i]=='f' || s[i]=='F')
a=a+1;
else if (s[i]=='g' || s[i]=='G')
a=a+1;
else if (s[i]=='h' || s[i]=='H')
a=a+1;
else if (s[i]=='i' || s[i]=='I')
a=a+1;
else if (s[i]=='j' || s[i]=='J')
a=a+1;
else if (s[i]=='k' || s[i]=='K')
a=a+1;
else if (s[i]=='l' || s[i]=='L')
a=a+1;
else if (s[i]=='m' || s[i]=='M')
a=a+1;
else if (s[i]=='n' || s[i]=='N')
a=a+1;
else if (s[i]=='o' || s[i]=='O')
a=a+1;
else if (s[i]=='p' || s[i]=='P')
a=a+1;
else if (s[i]=='q' || s[i]=='Q')
a=a+1;
else if (s[i]=='r' || s[i]=='R')
a=a+1;
else if (s[i]=='s' || s[i]=='S')
a=a+1;
else if (s[i]=='t' || s[i]=='T')
a=a+1;
else if (s[i]=='u' || s[i]=='U')
a=a+1;
else if (s[i]=='v' || s[i]=='V')
a=a+1;
else if (s[i]=='w' || s[i]=='W')
a=a+1;
else if (s[i]=='x' || s[i]=='X')
a=a+1;
else if (s[i]=='y' || s[i]=='Y')
a=a+1;
else if (s[i]=='z' || s[i]=='Z')
a=a+1;
}//end of for
// cout<<"There are "<<a<<" letters 'a' in the string";
}//END OF WHILE
// we know the max length of the sequence in consideration
// what we want is that to pad the sequences with "-" as to
// make the lenght equal for the sequences
//cout<<"The max length is "<< max<<" in the sequence file"<<endl;
while (inFile1 >> t) {
b=0;
cout << t;
for (j=0;j<=strlen(t)-1;j++){
if (t[j]=='a' || t[j]=='A')
b=b+1;
else if (t[j]=='-' || t[j]=='_')
b=b+1;
else if (t[j]=='b' || t[j]=='B')
b=b+1;
else if (t[j]=='c' || t[j]=='C')
b=b+1;
else if (t[j]=='d' || t[j]=='D')
b=b+1;
else if (t[j]=='e' || t[j]=='E')
b=b+1;
else if (t[j]=='f' || t[j]=='F')
b=b+1;
else if (t[j]=='g' || t[j]=='G')
b=b+1;
else if (t[j]=='h' || t[j]=='H')
b=b+1;
else if (t[j]=='i' || t[j]=='I')
b=b+1;
else if (t[j]=='j' || t[j]=='J')
b=b+1;
else if (t[j]=='k' || t[j]=='K')
b=b+1;
else if (t[j]=='l' || t[j]=='L')
b=b+1;
else if (t[j]=='m' || t[j]=='M')
b=b+1;
else if (t[j]=='n' || t[j]=='N')
b=b+1;
else if (t[j]=='o' || t[j]=='O')
b=b+1;
else if (t[j]=='p' || t[j]=='P')
b=b+1;
else if (t[j]=='q' || t[j]=='Q')
b=b+1;
else if (t[j]=='r' || t[j]=='R')
b=b+1;
else if (t[j]=='s' || t[j]=='S')
b=b+1;
else if (t[j]=='t' || t[j]=='T')
b=b+1;
else if (t[j]=='u' || t[j]=='U')
b=b+1;
else if (t[j]=='v' || t[j]=='V')
b=b+1;
else if (t[j]=='w' || t[j]=='W')
b=b+1;
else if (t[j]=='x' || t[j]=='X')
b=b+1;
else if (t[j]=='y' || t[j]=='Y')
b=b+1;
else if (t[j]=='z' || t[j]=='Z')
b=b+1;
}//end of for
// cout << "This is b before while" <<b << endl;
if(t[0]=='>'){
cout<<endl;
}
if(t[0]!='>'){
while(b<max){
cout << "-";
b++;
}//while(b<max)
cout << endl;
}//end of if
// cout << "This is b after while" <<b <<endl;
}//end of while
return 0;
}
Any help would be appreciable.
Thanks