대문자로 된 문자열을 파일에 쓰고 그 다음 소문자로 화면에 표시해야합니다. 그 후, 새로운 텍스트 (소문자)를 파일에 써야합니다. 코드를 작성했지만 작동하지 않습니다. 파일을 실행하면 파일이 손상되지 않고 소문자로 변환되지 않습니다.C로 파일 읽기 및 쓰기
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
void main(void) {
int i;
char date;
char text[100];
FILE *file;
FILE *file1;
file = fopen("C:\\Users\\amzar\\Desktop\\PC\\Pregatire PC\\Pregatire PC\\file\\da.txt","r");
file1 = fopen("C:\\Users\\amzar\\Desktop\\PC\\Pregatire PC\\Pregatire PC\\file\\da.txt","w");
printf("\nSe citeste fisierul si se copiaza textul:\n ");
if(file) {
while ((date = getc(file)) != EOF) {
putchar(tolower(date));
for (i=0;i<27;i++) {
strcpy(text[i],date);
}
}
}
if (file1) {
for (i=0;i<27;i++)
fprintf(file1,"%c",text[i]);
}
}
귀하의 컴파일러를 하드 코딩이 코드에 대한 진단 메시지를 발행 했어야의,
text
에 널 (NULL) 종료를 추가하고 확인하기 위해 두 번째 루프를 변경했습니다. 그들을 읽으십시오. – EOF