목적의 텍스트 변환 : .txt 파일로 변환하는 간단한 코드를 만듭니다 :.txt 파일
마다 '나는', 'E', 'A', 'S'와 'O를 '을 각각'1 ','3 ','4 ','5 '및'0 '으로 변환합니다.
처음에는 아주 간단하게 만들었지 만 여러 줄의 텍스트는 처리 할 수 없었습니다. 그래서 프레이즈와 행을 행렬로 처리하려고했지만 여전히 작동하게 만들 수는 없습니다. 코드는 다음과 같습니다.
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *arquivo;
char frase[100][100];
int i = 0;
int j = 0;
//adress of the initial text file
arquivo = fopen("C:\\Users\\xand\\Desktop\\ex1.txt", "r");
//transfering every line of the file into a matrix
while (!feof(arquivo))
{
fgets(frase[100][i],100, arquivo);
i++;
}
fclose(arquivo);
//converting the letters to numbers
for(j = 0; j < 100; j++)
{
while(frase[i][j] != '\0')
{
if(frase[i][j] == 'i' || frase[i][j] == 'I')
{
frase[i][j] = '1';
}
if(frase[i][j] == 'e' || frase[i][j] == 'E')
{
frase[i][j] = '3';
}
if(frase[i][j] == 'a' || frase[i][j] == 'A')
{
frase[i][j] = '4';
}
if(frase[i][j] == 's' || frase[i][j] == 'S')
{
frase[i][j] = '5';
}
if(frase[i][j] == 'o' || frase[i][j] == 'O')
{
frase[i][j] = '0';
}
i++;
}
}
arquivo = fopen("ex1 criptografado.txt", "w");
//here is where I believe to be the problem
//It doesn't even create the new file. Im not sure if using matrix is the ideal solution to fprintf a multi-lined text to a file
for(j = 0; j < 100; j++)
{
i = 0;
while(frase[i][j] != '\0')
{
fprintf(arquivo, "%s", frase[i][j]);
i++;
}
fprintf(arquivo, "\n");
}
fclose(arquivo);
return 0;
}
코드는 컴파일되지만 실행하려고하면 충돌합니다. 누구든지이 문제에 대한 해결책을 도울 수 있습니까?
['이 매트릭스는 당신을 ... 흰 토끼를 따르라. '] (http://www.youtube.com/watch?v=Smwrw4sNCxE) – jxh