나는 c로 프로그래밍하는 것이 정말 새롭다 고 말하기 시작한다.헤더 파일과 파일 핸들링을 만드는 법
ok .... 질문이 동일하지 않습니다 ... 프로그램이 파일을 열고 더 이상 아무것도하지 않더라도 꽤 잘 보이는 많은 것들을 수정했습니다. 나는 낱단 경고 그러나 아무런 오류가있다. 걱정은 allmoust allways 동일합니다 ... 부적합한 포인터 유형 ... 제 코드를 보시고 저를 도와 주시겠습니까? 감사합니다
#include <stdio.h>
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// //
// Definitions - Informations to the preprocessor //
// //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define MAX_SIZE 1024
#define ERROROF "Could not open the file!!!"
#define SUCCESS "file sucessefuly opened!!!"
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// //
// Functions - Implementation of several functions //
// //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int counting_lines(int *ptr){
char c;
int lines=0;
do
{
c=fgetc(ptr);
if (c="\n"){
lines++;
}
}
while((c!=EOF));
return lines;
}
int freading_diff(int *ptr, int a, int numb_lines_total) /* Function definition */
{
char *lines2ptr;
char lines2[numb_lines_total-2*a];
char buffer[MAX_SIZE];
int i;
for (i=0; i<numb_lines_total-2*a; i++){
lines2[i]=fgets(buffer, MAX_SIZE, ptr);
}
return &lines2ptr;
}
int freading_common(int *ptr1, int *ptr2, int a) /* Function definition */
{
char *lines1ptr;
char lines1[2*a];
lines1ptr=lines1[0];
char buffer[MAX_SIZE];
int i=0;
for (i=0; i<a; i=i+2){
lines1[i]=fgets(buffer, MAX_SIZE, ptr1);
lines1[i+1]=fgets(buffer, MAX_SIZE, ptr2);
}
return lines1ptr;
}
void screen_printing(char *lines1ptr, char *lines2ptr, int a, int numb_lines_total)
{
int i=0;
for (i=0; i<2*a; i++)
{
printf(lines1ptr+i);
}
for (i=0; i<numb_lines_total-2*a; i++)
{
printf(lines2ptr+i);
}
}
void main(void)
{
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// //
// Opening the files //
// //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
FILE *ptr1;
FILE *ptr2;
char filename1[255]; //variable to store the name of the first file
char filename2[255];
printf("First file : "); //prompts the user about the name of the first file
scanf("%63s", filename1);
printf("Second file : "); //prompts the user about the name of the first file
scanf("%63s", filename2);
if((ptr1 = fopen(filename1,"r")) == NULL) //checks if the first file can be opened
{
printf("%s %s \n",ERROROF, filename1);
return -1;
} else printf("%s %s ADDRESS %d\n",SUCCESS, filename1, &ptr1);
if((ptr2 = fopen(filename2,"r")) == NULL) //checks if the first file can be opened
{
printf("%s %s \n",ERROROF, filename2);
return -1;
}else printf("%s %s ADDRESS %d\n",SUCCESS, filename2, &ptr2);
int numb_lines_total=0;
int a=0, b=0;
int lines1=0, lines2=0;
int *pointerline1, *pointerline2;
int readlines1, readlines2;
pointerline1=&readlines1;
pointerline2=&readlines2;
lines1=counting_lines(ptr1);
lines2=counting_lines(ptr2);
numb_lines_total = lines1+lines2;
printf("First file has %d lines. Second file has %d lines. %d lines will be printed on the screen\n",lines1, lines2, numb_lines_total);
if (lines1<lines2)
{
a= lines1;
b= 2*a+1;
readlines1=freading_diff(ptr2, a, numb_lines_total);
} else if (lines1>lines2)
{
a= lines2;
b= 2 * a + 1;
readlines1=freading_diff(ptr1, a, numb_lines_total);
} else {
a= lines1;
}
readlines2=freading_common(ptr1, ptr2, a);
screen_printing(pointerline1, pointerline2, a, numb_lines_total);
fclose(ptr1);
fclose(ptr2);
return;
}
'char x'는 전체 파일 이름이 아닌 단일 문자입니다. 'fopen'을 체크하면'const char * filename' 매개 변수를 취합니다. 아마도 귀하의 기능도 그렇게해야합니다. –