problems with opening files and pointers...
hey!
i'm starting to learn c programming language and i'm having a lot of trouble with analising a file and read its characters and then copy them to another file... also i have a lot of problems with pointers and arrays... here's my code and remember n00b alert!! :)
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char incluir[]={'#','i','n','c','l','u','i','r',' ','\"'};
char definir[]={'#','d','e','f','i','n','i','r',' '};
char esquecer[]={'#','e','s','q','u','e','c','e','r',' '};
void fazincluir(linha){
int i=9;
int j=0;
int caracteracopiar;
char nomedofile[1024];
while (&linha[i] != '\"'){
nomedofile[j]=linha [i];}
nomedofile[j]='\0';
fopen(nomedofile, "r");
while((caracteracopiar=fgetc(atoi(nomedofile))) != EOF)
fputc(caracteracopiar, ficheiroderesultado);
}
void analisa(FILE* ficheiro){
char* linha=(char*) malloc(sizeof(char)*1024);
while((fgets(linha, pre)) != EOF){
if ((strncmp(incluir, linha, 9)) > 0)
fazincluir(linha);
else if ((strncmp(esquecer, linha, 10)) > 0)
fazesquecer(linha);
else if ((strncmp(definir, linha, 9)) > 0)
fazdefinir(linha);
}
}
int main(int argc, char* argv[]){
FILE* pre;
pre=fopen (argv[1], "r");
if(pre == NULL)
printf("Erro: Impossivel abrir ficheiro\n");
else analisa(pre);
return 0;
}
i get the following compilation errors:
Code:
proj2-1.c: In function `fazincluir':
proj2-1.c:14: subscripted value is neither array nor pointer
proj2-1.c:15: subscripted value is neither array nor pointer
proj2-1.c:18: warning: passing arg 1 of `fgetc' makes pointer from integer without a cast
proj2-1.c:19: `ficheiroderesultado' undeclared (first use in this function)
proj2-1.c:19: (Each undeclared identifier is reported only once
proj2-1.c:19: for each function it appears in.)
proj2-1.c: In function `analisa':
proj2-1.c:25: `pre' undeclared (first use in this function)
proj2-1.c:25: too few arguments to function `fgets'
proj2-1.c:25: warning: comparison between pointer and integer
proj2-1.c:29: warning: implicit declaration of function `fazesquecer'
proj2-1.c:31: warning: implicit declaration of function `fazdefinir'
PS: nevermind the implicit declarations, the program is not done yet.