2010-11-03 2 views
0

Моя программа принимает два файла со словами, отсортированными как параметр, и выполняет смесь в один отдельный файл с именем final_sorted.txt.the программа работает успешно и создает смешанный файл, даже игнорируя повторяющиеся слова, но компилятор сообщает мне некоторые предупреждения, которые не так удалены.предупреждение передать аргумент 1 из 'fopen' из несовместимого типа указателя

[email protected]:~/Escritorio/mezclar (2)$ gcc meclapro.c -o mixmeclapro.c: In function ‘mix_files’: 
meclapro.c:10: warning: passing argument 1 of ‘fopen’ from incompatible pointer type 
/usr/include/stdio.h:249: note: expected ‘const char * __restrict__’ but argument is of type ‘char **’ 
meclapro.c:11: warning: passing argument 1 of ‘fopen’ from incompatible pointer type 
/usr/include/stdio.h:249: note: expected ‘const char * __restrict__’ but argument is of type ‘char **’ 
meclapro.c: In function ‘main’: 
meclapro.c:69: warning: passing argument 1 of ‘mix_files’ from incompatible pointer type 
meclapro.c:6: note: expected ‘char **’ but argument is of type ‘char *’ 
meclapro.c:69: warning: passing argument 2 of ‘mix_files’ from incompatible pointer type 
meclapro.c:6: note: expected ‘char **’ but argument is of type ‘char *’ 

это мой код, который принимает, который принимает параметр командной строки

#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 

void mix_files(char **file1, char **file2){ 

    FILE *a1, *a2, *output; 
    char aux1 [10000],aux2 [10000]; 
    a1 = fopen(file1, "r"); 
    a2 = fopen(file2, "r"); 
    ouput = fopen ("final.txt", "w+"); 

    // read the first line of each file: 
    fscanf(a1,"%s",aux1); 
    fscanf(a2,"%s",aux2); 
    // loop, while !feof for both file 
    while(!feof(a1) && !feof(a2)) { 
     // Select the line to add 
     if(strcasecmp(aux1,aux2) < 0){ 
      // add the line 
      fprintf(output,"%s\n",aux2); 
      //read the next line from aux2 
      fscanf(a2,"%s",aux2); 
     } 

     else if(strcasecmp(aux1,aux2)>0){ 
      fprintf(salida,"%s\n",aux1); 
      fscanf(a1,"%s",aux1); 
     } 

     if (strcasecmp(aux1,aux2)==0){ 
      //printf("repetidas\n"); 
      fprintf(salida,"%s\n",aux1); 
      fscanf(a1,"%s",aux1); 
      fscanf(a2,"%s",aux2); 
     } 
    } 

    if(!feof(a1)){ 
     while(!feof(a1)) { 
      fscanf(a1,"%s",aux1); 
      fprintf(salida,"%s\n",aux1); 
     } 
    } 
    if(!feof(a2)){ 
     while(!feof(a2)) { 
      fscanf(a2,"%s",aux2); 
      fprintf(salida,"%s\n",aux2); 
     } 
    } 

} 

int main(int argc, char *argv[]){ 

    mix_files(argv[2], argv[1]); 

    return(0); 
} 

Я хотел бы кто-то, чтобы помочь мне найти причину предупреждения и как я могу исправить, заранее спасибо за ваши ответы, извините за мой английский

ответ

4

Изменение:

void mix_files(char **file1, char **file2){ 

к:

void mix_files(char *file1, char *file2){ 

или еще лучше:

void mix_files(const char *file1, const char *file2){ 

Вы тогда проездом правильный тип (символ *) от основной до mix_files, и это, в свою очередь, также будет решить эту проблему, когда вы звоните Еореп.

Смежные вопросы