Я пытаюсь сделать простую программу текстового редактора на C, но у меня есть эта странная ошибка. Когда я дойду до первой пользовательской подсказки, программа выйдет из строя. Вот мой код:Ошибка в текстовом редакторе Программа
#include <stdio.h>
int main()
{
FILE *filenew;
char firstchoice[200];
char filenamenew[200];
char overwrite;
char *textwrite;
char *filenameopen;
FILE *fileopen;
char readchar;
char *textopen;
start:
puts("Welcome to the Texter Text Editor!");
printf("\n");
printf("\n");
puts("Type ~N~ to create a new document,");
puts("Type ~O~ to open an existing document,");
puts("And type ~Q~ to quit.");
scanf("%s",&firstchoice);
if(firstchoice=="~N~" || firstchoice=="~n~")
{
puts("Enter the filename of the new document:");
scanf("%s",&filenamenew);
filenew = fopen(filenamenew,"r");
if(filenew)
{
fclose(filenew);
printf("%s already exists!\nDo you wish to overwrite it? [Y/N]",filenamenew);
overwrite=getchar();
if(overwrite=='y' || overwrite=='Y')
{
filenew=fopen(filenamenew,"w");
goto textnew;
}
else if(overwrite=='N' || overwrite=='n')
{
goto start;
}
}
textnew:
if(!filenew)
{
do
{
scanf("%s",textwrite);
fprintf(filenew,"%s",textwrite);
}
while(textwrite!="~Q~" && textwrite!="~q~");
}
}
else if(firstchoice=="~q~" || firstchoice=="~Q~")
{
return(0);
}
else if (firstchoice=="~o~" || firstchoice=="~O~")
{
printf("Enter the filename of the document you want to open:\n");
scanf("%s",filenameopen);
fileopen=fopen(filenameopen,"r+");
if(!fileopen)
{
puts("File does not exist!");
goto start;
}
else
{
do
{
readchar=getc(fileopen);
putchar(readchar);
}
while(readchar!=EOF);
do
{
scanf("%s",textopen);
fprintf(fileopen,"%s",textopen);
}while(textopen!="~Q~" && textopen!="~q~");
}
}
return(0);
}
Я знаю, что это грязно, со всеми GOTOS и переключение с массив символов на символ указателя, но, пожалуйста, попробуйте помочь.
не торопитесь и попробуйте переформатировать и перестроить код. не для нас, а для себя. если окупается. – fazo