Hello everyone!
I'm a beginner and I was facing a problem here.
I am trying to use scanf to input filenames as strings to different indexes in the array char **filenames.
For example:
filenames[0] = "lol1.txt";
filenames[1] = "lol2.txt";
filenames[2] = "lol3.txt";
filenames[3] = "lol4.txt";
filenames[4] = "lol5.txt";
But my code doesn't seem to work:
Any ideas on what I'm doing wrong here?Code:int totalfiles = 0; printf ("Enter the total number of files to be merged:"); scanf ("%d", &totalfiles); char **filenames; filenames = (char**)calloc(sizeof(char**), totalfiles); // I tried using the code below but it messes up the program int n = 0; while ( n < totalfiles ) { printf ("File number %d:", n+1); scanf ("%s", filenames[n]); // I'm assuming the problem is in this line n++; }
Thanks!