So i have this code and I want it to run like this
cmd> new
enrer your array
cmd> list
*displays array*
cmd>
Code:
#include <stdio.h>
#include <string.h>
#define SIZE 200
#define HISTORY_SIZE 10 /*the maximum size of the history*/
//#define MAX_STRING_LEN 100 /*the maximum size of strings*/
#define MAX_CMD_LEN 10/*the maximum size of a command*/
void getString( char* );
void printString (const char *);
void appendString(char *str, char *newstr);
int main()
{
char command[MAX_CMD_LEN];
char string[SIZE];
char newstr[SIZE];
int flag;
do {
printf("cmd> ");
fgets(command, MAX_CMD_LEN, stdin);
if(strcmp(command, "new")!=0) {
getString(string);
}
if(strcmp(command, "list")!=0) {
printString(string);
}
if(strcmp(command, "append")!=0) {
appendString(string, newstr);
}
}while (flag!=1);
return 0;
}
void getString(char *string)
{
printf("Please enter your string");
fgets(string, SIZE, stdin);
}
void printString (const char *string)
{
printf( "\n\nHere is the text you entered:\n%s\n", string);
}
void appendString(char *string, char *newstr)
{
printf("Enter string to append");
fgets(newstr, SIZE, stdin);
strcat(string,newstr);
fgets(string,SIZE, stdin);
}