比较单词分组的文件内容

时间:2016-09-11 21:29:27

标签: c

背景: 我目前正在开展一个项目。主要目标是读取文件并比较单词分组。只有用户交互才能指定组长度。我的程序被放入一个目录中。在该目录中,将有多个文本文件(最多30个)。我用 system(" ls / home / .....> inputfile.txt");

    $write_result = socket_write($msgsock, $talkback, strlen($talkback));
    echo "Length Wrote: " .  $write_result . "\n";
    socket_close($msgsock);

从那里,我打开inputfile.txt中的文件来读取它们的内容。 现在到实际的问题/问题部分。 我正在使用的方法是队列,因为FIFO。 (代码" link.c":http://pastebin.com/rLpVGC00

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

link.c

当我使用link.c和main(Start11.c)

编译时,我收到两个警告
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include "linkedlist.h"

struct linkedList
{  
   char *data;
   int key;
   int left;
   int right;
   int size;
};

LinkedList createLinkedList(int size)
{
   LinkedList newLL = malloc(sizeof *newLL);
   newLL->data  = malloc(sizeof(int) * (size+1));
   newLL->size  = size;
   newLL->left  = 0;
   newLL->right = 0;
   return newLL;
}

bool isFull(LinkedList LL)
{
    return abs(abs(LL->left)- abs(LL->right)) == LL->size;
}

void insertFront(LinkedList LL, char  *newInfo)
{
    if(isFull(LL)) 
    {
        printf("FULL");
        exit(1);
    }

   LL->data[((--(LL->left) % LL->size) + LL->size) % LL->size] = newInfo;
}

bool isEmpty(LinkedList LL)
{
    return LL->left == LL->right;
}

const char * removeEnd(LinkedList LL)
{
    if(isEmpty(LL))
    {
        return "EMPTY";
        //exit(1);
    }
    return LL->data[((--(LL->right) % LL->size) + LL->size) % LL->size];
}

FULL start11.c代码:http://pastebin.com/eskn5yxm。 从大量的read()函数我有疑问:

    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];
 ^

在我尝试比较文件的原因之前,这两个警告是不是正确的? (是的,我意识到我&#34;硬编码&#34;比较。这只是暂时的,直到我得到一些这个......) 我将头文件作为注释发布。不要让我发布两个以上的链接。 补充说明: removeEnd()返回&#34; EMPTY&#34;如果有什么东西可以删除。 insertFront()是一个void函数。 在我创建这个帐户之前我可以发帖,我读了一个关于strttok的前一个问题,以及如果我想插入一些我必须strdup()它。 我没有将我的自由函数添加到我的read()函数中。我也会这样做。

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, " ") ) { puts(token2); ++y; stringArray[y] = strdup(token2); insertFront(index[i],stringArray[y]); } } } //Comparisons 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"); ++count; if(count == groupL) { ++groupV; } } if(take[z] == take3[z]) { printf("File 1 and File 3 are similar\n"); ++count2; if(count == groupL) { ++groupV2; } } } pastebin.com/NTnEAPYE

start.h

#ifndef START_H #define START_H #include "linkedlist.h" void read(LinkedList LL,char* filename, int lineL); #endif pastebin.com/ykzbnCTV

linkedlist.h

1 个答案:

答案 0 :(得分:1)

主要问题是removeEnd(分别为insertFrom)函数:

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

你在第一次回归中返回const char *但在第二次回归中返回char,因此警告是严重的。

当你在调用者中将返回值与"EMPTY"进行比较时,它是错误的:你应该使用strcmp而不是比较可能相同的数组,具体取决于编组器字符串在同一位置,但只是偶然(而不是便携式!)

相关问题