If I open enter sentence something like this "asdasd asd asdas sad" for any char scanf
it will skip other scanfs.
for exapmle if I type for obligation
scanf this sentence
it will write for obligation scanf
this and next scanf will be skipped but automaticly will be field with sentence word
...
Here is the code:
while(cont == 1){
struct timeval tv;
char str[12];
struct tm *tm;
int days = 1;
char obligation[1500];
char dodatno[1500];
printf("Enter number of days till obligation: ");
scanf(" %d", &days);
printf("Enter obligation: ");
scanf(" %s", obligation);
printf("Sati: ");
scanf(" %s", dodatno);
if (gettimeofday(&tv, NULL) == -1)
return -1; /* error occurred */
tv.tv_sec += days * 24 * 3600; /* add 6 days converted to seconds */
tm = localtime(&tv.tv_sec);
/* Format as you want */
strftime(str, sizeof(str), "%d-%b-%Y", tm);
FILE * database;
database = fopen("database", "a+");
fprintf(database, "%s|%s|%s
",str,obligation,dodatno);
fclose(database);
puts("To finish with adding enter 0 to continue press 1
");
scanf(" %d", &cont);
}
See Question&Answers more detail:os