Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > IT форум > Помощь студентам
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 18.12.2018, 21:13   #1
liberty_
Новичок
Джуниор
 
Регистрация: 06.11.2018
Сообщений: 6
По умолчанию Вывести буквенное выражении на СИ (проверить код)

Если вводить цифры, то всё ок, если буквы, то выводит тоже цифры. Где и что надо исправить, подскажите, пожалуйста.

Код:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define TRUE 1
struct List
{
 int x;
 struct List * Next;
};
struct List * CreateList(void);
void DisplayList( struct List* );

void RemoveTermBegin( struct List** );
void RemoveTermTag( struct List* );
void RemoveTermEnd( struct List* );
void AddTermBegin( struct List** );
void AddTermEnd(struct List* );
void AddTermTag(struct List* );
void FreeList(struct List** );
int main(void)
{
 struct List* Begin;
 char Key;
 while(TRUE)
 {
 printf( "\nEnter the number- the mode of ”“operations with Lists: "
 "\n 1 - FORMATION OF THE LIST");
 printf( "\nEnter the number- the mode of ”“operations with Lists: "
"\n 2 - VIEWING OF CONTENTS OF THE LIST" );
printf( "\nEnter the number- the mode of ”“operations with Lists: "
"\n 3 - REMOVE THE ELEMENT FROM");

printf( "\nEnter the number- the mode of ”“operations with Lists: "
"\n 3 - REMOVE THE ELEMENT FROM “THE BEGIN OF LIST");


printf( "\nEnter the number- the mode of ”“operations with Lists: "
"\n 4 - REMOVE THE ELEMENT FROM ”“THE MIDLE OF LIST" );

printf( "\nEnter the number- the mode of ”“operations with Lists: "
"\n 5 - REMOVE THE ELEMENT FROM""THE END OF LIST" );

printf( "\nEnter the number- the mode of ”“operations with Lists: "
"\n 6 - ADD THE ELEMENT IN THE ”“BEGIN OF LIST");


printf( "\nEnter the number- the mode of ”“operations with Lists: "
 "\n 7 - ADD THE ELEMENT IN THE ”“END OF LIST");

printf( "\nEnter the number- the mode of ”“operations with Lists: "
 "\n 8 - ADD THE ELEMENT AFTER" "ELEMENT-KEY OF LIST");


printf( "\nEnter the number- the mode of ”“operations with Lists: "
"\n 9 - END OF WORK\n");


 fflush( stdin );
 scanf("%c",&Key);
system("cls");
 switch (Key)
 {
 case '1':
 system("cls");
 Begin = CreateList();
 printf("\n\nPress any key to return in ”“the menu...\n");
 getch();

system("cls");
 break;
 case '2':
 system("cls");
 DisplayList(Begin);
 printf("\n\nPress any key to return in ”“the menu...\n");
 getch();
 system("cls");
 break;
 case '3':
system("cls");
 RemoveTermBegin(&Begin);
 printf("\n\nPress any key to return in ”“the menu...\n");
 getch();
 system("cls");
 break;
 case '4':
 system("cls");
 RemoveTermTag(Begin);
 printf("\n\nPress any key to return in ”“the menu...\n");
 getch();
 system("cls");
 break;
 case '5':
 system("cls");
 RemoveTermEnd(Begin);
 printf("\n\nPress any key to return in ”“the menu...\n");
 getch();
 system("cls");
 break;
 case '6':
 system("cls");
 AddTermBegin(&Begin);
 printf("\n\nPress any key to return in ”“the menu...\n");
 getch();

 system("cls");
 break;
 case '7':
 system("cls");
 AddTermEnd(Begin);
 printf("\n\nPress any key to return in ”“the menu...\n");
 getch();
 system("cls");
 break;
 case '8':
 system("cls");
 AddTermTag(Begin);
 printf("\n\nPress any key to return in ”“the menu...\n");
 getch();
system("cls");
 break;
 case '9':
 FreeList(&Begin);
 DisplayList(Begin);
 printf("\n\nPress any key to ”“exit...\n");
getch();
 return 0;
 default:
system("cls");
 printf("\nIncorrect input!!! Try ”“again!!!\n");
 printf("\n\nPress any key to return in ”“the menu...\n");
 getch();
system("cls");
 break;
 }
 }
}
struct List* CreateList(void)
{
 struct List* Begin = NULL, *Previos = NULL,

*Current= NULL;
 char Ok = 'y';
 while (Ok == 'y')
 {
 printf("\nEnter the numbers of List: ");
 Current =
( struct List*)malloc(sizeof(struct List));
 if (Begin==NULL)
Begin = Current;
 else
Previos -> Next = Current;
 Previos = Current;
 scanf("%d",&Current -> x);
 fflush( stdin );
 printf("\nContinue? (Y/N):");
 scanf("%c",&Ok);
 }
 Previos -> Next = NULL;
 return Begin;
}
void DisplayList(struct List* Begin)
{
 struct List* Current = Begin;
if ( Begin == NULL )
 {
 printf("List is empty\n");
 return;
 }
 printf("\nThe List of numbers:\n");
 while (Current)
 {
 printf("%d ",Current -> x);
 Current = Current -> Next;
 }
 printf("\n");
}

void RemoveTermBegin(struct List** Begin)
{
 struct List** Current = Begin;
 *Begin = (*Current) -> Next;
 free(Current);
}
void RemoveTermTag(struct List* Begin)
{
 struct List* Current = Begin, *Previos = Current;
 int NumberTag;
 printf("\nEnter number-key: ");
 scanf("%d",&NumberTag);
 while ( Current )
 {
 if ( Current -> x == NumberTag )
 {
 Previos -> Next = Current -> Next;
 free(Current);
 Current = Previos -> Next;
 }
 else
 {
 Previos = Current;
 Current = Current -> Next;
 }
 }
}
void RemoveTermEnd(struct List* Begin)
{
 struct List* Current = Begin, *Previos;
 while (Current -> Next)
 {
 Previos = Current;
 Current = Current -> Next;
 }
 Previos -> Next = NULL;
 free(Current);
}

void AddTermBegin(struct List** Begin)
{
 struct List* Current =
(struct List*)malloc(sizeof(struct List));
 printf("\nEnter number: ");
 scanf("%d",&Current -> x);
 Current -> Next = *Begin;
 *Begin = Current;
}
void AddTermEnd(struct List* Begin)
{
 struct List* Current = Begin, *Previos;
 while (Current)
 {
 Previos = Current;
 Current = Current -> Next;
 }
 Current = (struct List*)malloc(sizeof(struct List));
 Previos -> Next = Current;
 printf("\nEnter the number:\n");
 scanf("%d",&Current -> x);
 Current -> Next = NULL;
}
void AddTermTag(struct List* Begin)
{
 struct List* Current = Begin, *Previos = Current;
 int NumberTag;
 printf("\nEnter number-tag: ");
 scanf("%d",&NumberTag);
 while ( Current )
 {
 if ( Current -> x == NumberTag )
 {
 Previos = Current;
 Current =
(struct List*)malloc(sizeof(struct List));

 Current -> Next = Previos -> Next;
 Previos -> Next = Current;
 printf("\nEnter the number:\n");
 scanf("%d",&Current -> x);
 break;
 }
 else
 {
 Previos = Current;
 Current = Current -> Next;
 }
 }
}
void FreeList(struct List** Begin)
{
 struct List* Current = *Begin;
 while (Current)
 {
 *Begin = (*Begin) -> Next;
 free(Current);
 Current = *Begin;
 }
}
liberty_ вне форума Ответить с цитированием
Старый 18.12.2018, 23:09   #2
p51x
Старожил
 
Регистрация: 15.02.2010
Сообщений: 15,707
По умолчанию

А где вы вводите символы, кроме y?
p51x вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
[C#] ошибка: "Несоответствие типов данных в выражении условия отбора". Код внутри Atljh96 C# (си шарп) 1 25.06.2017 10:15
Проверить код Devdev12 Общие вопросы C/C++ 2 11.12.2014 19:37
Проверить код Artem131 Общие вопросы C/C++ 0 29.04.2013 22:47
Как преобразовать цыфры в буквенное их выражение Makspane Общие вопросы Delphi 17 08.05.2012 01:07
проверить код delfin07 Assembler - Ассемблер (FASM, MASM, WASM, NASM, GoASM, Gas, RosAsm, HLA) и не рекомендуем TASM 9 21.02.2012 13:58