2014-01-20 90 views
0

我一直在试图将两个数组传递给一个函数,以便我可以比较它们,但是如何传递数组并开始比较行。我遇到错误,如不兼容的指针类型传递给类型const char ????这里是我迄今为止...有麻烦在顶部排序功能将两个二维数组传递给函数进行比较

//

#define MAXROWS 30 
#define MAXCOLS 100 
#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 

char topsort(char, int, char, int);  

int main(int argc, const char * argv[]) 
{ 
    //array for all of the word's in the file 
    char list[MAXROWS][MAXCOLS], line[MAXCOLS], constraint[MAXROWS][MAXCOLS]; 
    FILE *list_sort; 
    int listcols = 0, listrows = 0, concols = 0, conrows = 0; 

    //open the sequential access file and make sure its found 
    list_sort = fopen("/Volumes/JENN/cpma stuff/introcompsys/list sort.txt","r"); 
    if(list_sort == NULL){ 
     printf("can't open file"); 
     exit(EXIT_FAILURE); 
    } 

    while(fgets(line, sizeof(line), list_sort) != NULL) 
    { 
     if(index(line, ',') == NULL){ 
      for(listcols =0; listcols< strlen(line)-1 ;++listcols) { 
       list[listrows][listcols] = line[listcols]; 
      } 
      list[listrows][listcols] = '\0'; 
      printf("%s\n", list[listrows]); //print each row of the list to check 
      ++listrows; 
     } 
     else{ 
      for(concols =0; concols< strlen(line)-1 ;++concols) { 
       constraint[conrows][concols] = line[concols]; 
      } 
      constraint[conrows][concols] = '\0'; 
      printf("%s\n", constraint[conrows]); //print each row of the constraint to 
      //check 
      ++conrows; 
     } 

    } 
} 
char topsort(char s1[][MAXCOLS], int listrows, char s2[][MAXCOLS], int conrows){ 
char sorted[MAXROWS][MAXCOLS]; 

while(the constraint array is not empty){  //pseudocode 
    int second = char *strchr(s2, ‘,’+ 2); 
    for(int i = 0; i < listrows ; i++){ 
     for(int j = 0; j < conrows; j++){ 
      strcspn(s2[j][second], s1[i]); 
     } 
    } 
} 

}

+0

你的函数声明在哪里? – haccks

+0

请将警告/错误添加到问题中。 –

+0

包含所有错误消息,包括行号。也是示例输入。 –

回答

-1

多个问题topsort IM的代码。这不会起作用。

这是一个坏主意:

char s1[][MAXCOLS] 

要么指定所有的尺寸大小,还是使用字符**。

这是错误的,原因有几个。

int length = strlen(s2[][]); 

你不给任何数组索引,你传递一个char这需要一个char *的功能,并且使用的是在一个while循环长度,从来没有改变它。

strlen(&s1) 

这是将char * * *传递给期望char *的函数。

strcspn(s2[i], s1[i]); 

将两个字符传递给一个带有char和char *的函数。另外你甚至不会看到结果。

+1

'char s1 [] [MAXCOLS]'是一个坏主意?在这种情况下,从'main'传递的参数(应该是)有一个签名'list [MAXROWS] [MAXCOLS]','char ** s1'是一个坏主意,因为数据是连续的,而不是一个指针数组。 –

+0

*或**在变量前面意味着什么?该函数显然不是“功能”....我不知道用于比较数组行中的值而不是指向它们的语法 – user3215644