Question
I'm having some issues with my C program. I need the program to find all MP3 files and print how far in distance the songs
I'm having some issues with my C program. I need the program to find all MP3 files and print how far in distance the songs are. AS of right now my prgram gives an error (ATTACHED) , I had the function commented out earlier and it does also compile fine but gives a segmentation fault. So, I'm thinking there is also an error with the malloc() call I used earlier. Ideally, after running the output needs to say (Ex: Green Day - Waiting.mp3, 2, Green Day - Warning.mp3). I have not made the print statement for that yet. Partial output is attached also. Any and all help is appreciated.
My CODE: **********************************************************
Using glob to read multiple mp3 files and finding
those with similar names using Wagner-Fischer alogorithm*/
#include
#include
#include
#include
static int editDist(char str1, char str2, int m, int n);
int main (int argc, char* argv[])
{
glob_t paths;
int csource;
char **p;
char *ext;
int dist;
ext = malloc(sizeof(char)* 100);/*SEGMENTATION FAULT HERE*/
ext = strcat("*.", argv[2]);
dist = atoi( argv[1]);
/* check and it works! printf("%d ", dist);*/
/*Finds all "mp3" in my directory*/
csource = glob(ext,dist,NULL,&paths);
if(csource == 0){
for(p=paths.gl_pathv; *p != NULL; ++p)
printf("%s ", *p); /* *p is the address of a string*/
globfree(&paths); /*frees memory*/
free(ext);
}
}
/*This is Wagner-Fischer algorithm*/
static int editDist(char str1, char str2, int m, int n){
int dp[m+1][n+1];
int i, j;
/*fill d[][] in bottom up manner*/
for(i=0; i
for(j=0; j
/*if fist string is empty, only option is to
remove all characters of second string*/
if(i==0)
dp[i][j] = j;
/*if second string is empty, only option is to
remove all characters of second string*/
else if(j==0)
dp[i][j] = i;
/*if last characters are the same, ignore last char
and recur for remaining string*/
else if(str1[i-1] == str2[j-1])
dp[i][j] = dp[i-1][j-1];
/*if the last character is different, consider all
possibilities and find the minimun*/
else
dp[i][j] = 1 + min(dp[i][j-1], /*insert*/
dp[i-1][j], /*remove*/
dp[i-1][j-1]); /*replace*/
}
}
return dp[m][n];
}
c In function 'editDist: c:34: warning: ISO C90 forbids variable-size array 'dp' c: 34: warning: ISO C90 forbids variable-size array 'dp' c:49: error: subscripted value is neither array nor pointer c:49: error: subscripted value is neither array nor pointerStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started