Я пытаюсь создать программу, которая добавляет письмо, которое вы даете к текущей строке, которая у него есть.У меня проблемы почти во всех областях, так как если я пытаюсь добавить письмо, это дает мне «ошибку сегментации».Я добавил комментарий о том, что должен делать каждый раздел. Буду признателен за помощь в этом проекте.
#include <stdio.h>
#include <string.h>
int main(void) {
int choice;
char str[20];
char str1;
while(1) {
printf("Give your choice: "); //Asks the choice from the menu
scanf("%i", &choice);
if(choice == 1) { //This choice adds a letter to the (empty) string
printf("Give a letter: ");
scanf("%s", str);
strcat(str, str1); }
else if(choice == 2) { //choice 2 clears the string
printf("");
scanf("%s", str1); }
else if(choice == 3) { //choice 3 prints what's in the string
printf("%s", str1); }
else { //if choice is wrong, it ends the program
printf("Faulty input!\n");
break; }
} }
Спасибо!