#include <iostream>
#include <fstream>
#include <cmath>
#include <bits/stdc++.h>
#include <string.h>
#define MAX_LEN 9999
using namespace std;
void printDNAarray(const char * dnaArray, int length){
cout<<"Printing DNA Array of length: "<<length<<endl;
for(int i=0; i<length; i++)
cout<<dnaArray[i];
cout<<endl;
}
char * processDNAString(string line){
char * arrayToSort = new char[line.length()];
for(int i=0; i< line.length();i++)
arrayToSort[i] = line[i];
return arrayToSort;
}
/*
* Selection Sorting Algorithm
*/
void selectionSort (char arrayToSort[][MAX_LEN], int n)
{
int i,j,min_idx;
char minStr[MAX_LEN];
for (i=0;i<n-1;i++)
{
int min_idx=i;
strcpy(minStr,arrayToSort[i]);
for(j=i+1;j<n;j++)
{
if (strcmp(minStr, arrayToSort[j])>0)
{
strcpy(minStr,arrayToSort[j]);
min_idx=j;
}
}
if (min_idx !=i)
{
char temp[MAX_LEN];
strcpy (temp, arrayToSort[i]);
strcpy(arrayToSort[i],arrayToSort[min_idx]);
strcpy(arrayToSort[min_idx],temp);
}
}
}
int main(int argc, char * argv[])
{
ifstream fin;
string line;
std::string cur_dir(argv[0]);
int pos = cur_dir.find_last_of("/\\");
string path = cur_dir.substr(0, pos);
std::cout << "path: " << cur_dir.substr(0, pos) << std::endl;
std::cout << "Exec file: " << cur_dir.substr(pos+1) << std::endl;
string filename = path + "/rosalind_dna.txt";
cout << "Opening dataset file: "<<filename<< endl;
fin.open(filename);
if(!fin){
cerr << "Unable to open rosalind_dna.txt file..."<<endl;
cerr << "Review your current working directory!!"<<endl;
exit(1);
}
while(fin){
getline(fin,line);
cout << line <<endl;
break;
}
cout<<endl;
char * dnaArray = processDNAString(line);
printDNAarray(dnaArray, line.length());
cout<<"Sorting DNA Array ..."<<endl;
//Implementation
selectionSort(dnaArray,line.length());
printDNAarray(dnaArray, line.length());
fin.close();
return 0;
}
I need help, it is to be a selectionsort algorithm but I can't make it work because these errors:
main.cpp:96:19: error: cannot convert ‘char*’ to ‘char (*)[9999]’
96 | selectionSort(dnaArray,line.length());
| ^~~~~~~~
| |
| char*
main.cpp:35:26: note: initializing argument 1 of ‘void selectionSort(char (*)[9999], int)’
35 | void selectionSort (char arrayToSort[][MAX_LEN], int n)
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~ ~~~~~^~~~~~~~~~~~~~~~~~~~~~