anchorman anchorman - 4 months ago 14
C Question

Comparing contents of files for groupings of words

I am currently working on a project. The main objective is to read files and compare groupings of words. Only user interaction will be to specify group length. My programs are placed into a directory. Inside that directory, there will be multiple textfiles(Up to 30). I use
system("ls /home/..... > inputfile.txt");

system("ls /home/..... > inputfile.txt");

From there, I open the files from inputfile.txt to read for their contents.
Now to the actual question/problem part.
The method I am using for this is a queue because FIFO. (Code "link.c":
I get two warnings when I compile with link.c and my main (Start11.c)

link.c: In function ‘insertFront’:
link.c:39:64: warning: assignment makes integer from pointer without a cast [enabled by default]
LL->data[((--(LL->left) % LL->size) + LL->size) % LL->size] = newInfo;
link.c: In function ‘removeEnd’:
link.c:54:5: warning: return makes pointer from integer without a cast [enabled by default]
return LL->data[((--(LL->right) % LL->size) + LL->size) % LL->size];

FULL start11.c code: .
From bulk of read() function that I have questions about:

fp = fopen(filename, "r");

//We want two word or three word or four word PHRASES

for (i = 0; fgets(name, 100, fp) != NULL && i < 31; i++)
char *token = NULL; //setting to null before using it to strtok
token = strtok(name, ":");
strtok(token, "\n");//Getting rid of that dirty \n that I hate
strcat(fnames[i], token);
char location[350];
//Copying it back to a static array to avoid erros with fopen()
strcpy(location, fnames[i]);
//Opening the files for their contents
fpp = fopen(location, "r");
printf("\nFile %d:[%s] \n", i+1, fnames[i]);

char* stringArray[400];
//Reading the actual contents
int y;
for(j = 0; fgets(info,1600,fpp) != NULL && j < 1600; j++)
for( char *token2 = strtok(info," "); token2 != NULL; token2 = strtok(NULL, " ") )
stringArray[y] = strdup(token2);

char take[20010],take2[200100], take3[200100],take4[200100];
int x,z;
int count, count2;
int groupV,groupV2;
for(x = 0; x < 10000; ++x)
if(removeEnd(index[0])!= "EMPTY")
take[x] = removeEnd(index[0]);
if(removeEnd(index[1])!= "EMPTY")
take2[x] = removeEnd(index[1]);
if(removeEnd(index[2])!= "EMPTY")
take3[x] = removeEnd(index[2]);
for(z = 0; z < 10; z++)
if(take[z] == take2[z])
printf("File 1 and File 2 are similar\n");
if(count == groupL)
if(take[z] == take3[z])
printf("File 1 and File 3 are similar\n");
if(count == groupL)

Are those two warnings before the reason why when I try to compare the files it'll not be correct? (Yes I realize I "hardcoded" the comparisons. That is just temporary till I get some of this down...)
I'll post header files as a comment. Won't let me post more than two links.
Additional notes:
removeEnd() returns "EMPTY" if there is if there is nothing left to remove.
insertFront() is a void function.
Before I created this account so I can post, I read a previous question regarding strttok and how if I want to insert something I have to strdup() it.
I have not added my free functions to my read() function. I will do that last too.


The main problem is around the removeEnd (resp. insertFrom) function:

const char * removeEnd(LinkedList LL)
  if (...)
    return "EMPTY";
     return LL->data[xxx];

you return a const char * in the first return but a char in the second return, hence the warning, which is a serious one.

And when you compare return value to "EMPTY" in the caller, it's just wrong: you should use strcmp instead of comparing arrays which may be the same depending on compilers which group same strings in the same location, but only by chance (and not portable!)