(난이도 : 下)
#include <stdio.h>
int main() {
char location[50];
printf("경로를 입력하세요 : ");
scanf("%s", location);
printf("\n사용자가 입력한 경로 : %s", location);
FILE* fp = fopen(location, "w");
if (fp == NULL) {
printf("File Error");
}
fputs("a", fp);
fclose(fp);
return 0;
}
(난이도 : 中)
#include <stdio.h>
int main()
{
char userInput[20];
char temp;
int i=0;
int index=0;
printf("검색할 문자열 : ");
scanf("%s", userInput);
printf("\n");
FILE *fp = fopen("a.txt", "r");
while(1){
temp=fgetc(fp);
if(temp==EOF) break;
if(temp==*(userInput+i)){
i++;
if(*(userInput+i)==NULL){
break;
}
}
else{
i=0;
index++;
}
}
if(temp==EOF)
printf("Not Equal\n");
else
printf("Equal\nindex : %d", index);
fclose(fp);
return 0;
}
(난이도 : 中下)
#include <stdio.h>
int main() {
FILE* fpa = fopen("a.txt", "r");
FILE* fpb = fopen("b.txt", "w");
if (fpa == NULL) {
printf("Read Error !! \n");
return 0;
}
if (fpb == NULL) {
printf("Write Error !! \n");
return 0;
}
int count = 0;
while (fgetc(fpa) != EOF) {
count++;
}
char temp;
for (int i = 0; i < count; i++) {
fseek(fpa, i, SEEK_SET);
temp = fgetc(fpa);
fputc(temp, fpb);
}
fclose(fpa);
fclose(fpb);
return 0;
}