So you are to read in integers c and m. C is the number of cases, m is the number of lines per case. After m, there are m lines containing any number of letters, no doubles (a-z). After those lines there is an int r, which is the solution number we want if we did recursion for every possible result having one letter from each line, forming a string.
There is a way to skip recursion, and go straight to the rank (int r) that we want. I am having a problem with my pointers by trying to send my struct into functions. all my errors pertain to my struct and sending my struct into my functions. Any help would be great. Here is a sample of my code.
#include <stdio.h>
#include <stdlib.h>
#define MAX 26
struct passwordT{
char letters[MAX];
int charCount;
int possibleSkips;
int solutionArray;
};
lines of chars.
passwordT* numOfSkips(passwordT *T, int *total, int m);
int getSol(int ps, int v, int m, int r);
int main(){
int i, j, k;
int c, m, r;
char p;
int total = 0;
scanf("%d", &c);
passwordT* ptrToPass;
ptrToPass = malloc(c*sizeof(passwordT));
for (i=0; i<c;i++){
scanf("%d", &m);
for(j=0;j<m;j++){
scanf("%s", &ptrToPass[j].letters);
}
for(j=0; j<m; j++){
ptrToPass[j].charCount = 0;
k=0;
p = ptrToPass[j].letters[0];
while(p!='\0'){
ptrToPass[j].charCount ++;
k++;
p = ptrToPass[j].letters[k];
}
}
scanf("%d", &r);
ptrToPass = numOfSkips(ptrToPass, &total, m);
for(j=0;j<m;j++)
ptrToPass[j].solutionArray = getSol(ptrToPass[j].possibleSkips, 1, m, r);
for(j=0;j<m;j++)
printf("%c", ptrToPass[j].letters[ptrToPass[j].solutionArray]);
}
return 0;
}
passwordT* numOfSkips(passwordT *T, int *total, int m){
passwordT *skippers;
int i = 0;
total times current lines char count
for(i=0;i<m;i++){
if(i==0){
skippers[i].possibleSkips = 1;
total = skippers[i].charCount;
}
else{
skippers[i].possibleSkips = total;
total = total * skippers[i].charCount;
}
}
}
int getSol(int ps, int v, int m,int r){
int sa = 0;
int i;
for(i=0; i<m; i++){
while(v <= r - ps){
sa ++;
v += sa;
}
}
return sa;
}
Here are my error lines
12: syntax error before
13: warning, data definition has no type or storage class
IN MAIN
28: passwordT undeclared, first use in this function ( so when i have passwordT* ptrToPass;)
28: ptrtoPass undeclared
IN numOfSkips
73: syntax error before
79: m undeclared (first use in this function) --> First time I use m in function numOfSkips
83: total undeclared (same situation as line 79)