In my C program i read three string "task_name", "task_trigger" and "task_number".
char task_name[255];
char task_trigger[10];
char task_number[10];
First, i read "task_name" :
void get(char *prompt, char *str, int size)
{
printf("%s", prompt);
fgets(str, size, stdin);
if (str[strlen(str) - 1] == '\n')
str[strlen(str) - 1] = '\0';
fflush(stdin);
}
get("Please enter the name for the system task you want", task_name, 255);
if (strlen(task_name) == 0)
{
strcpy(task_name, "TaskSystem");
}
After, i read "task_trigger" in a while and if "task_trigger" is equal to 1 i read task_number, when i get task_number, i concate it at the end of task_trigger :
while (strcmp(task_trigger, "1") != 0)
{
printf("1 - MINUTE - Run the task on specified minutes.\n");
if (strcmp(task_trigger, "1") == 0)
{
strcpy(task_trigger, "/MO MINUTE: ");
printf("%s", task_name);
get("How many minutes ? : ", task_number, 10);
strcat(task_trigger, task_number);
break;
}
}
When i run my program, everything is asked fine, but task_name is eual to ":", i don't know why..
What i have shared to you is a part of my program, the error is triggered at strcpy(task_trigger, "/MO MINUTE: ");
.
Thanks :)