fork download
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4. #define MAX_REMIND 50
  5. #define MSG_LEN 60
  6. int read_line(char str[] , int n);
  7.  
  8. int main( void )
  9. {
  10. char reminders[MAX_REMIND][MSG_LEN+3];
  11. char day_str[3] , msg_str[MSG_LEN+1];
  12. int day , i , j , num_remind=0;
  13.  
  14. for(;;){
  15. if( num_remind == MAX_REMIND){
  16. printf("-- No space left --\n");
  17. break;
  18. }
  19. printf(" Enter day and reminder : ");
  20. scanf("%2d", &day);
  21.  
  22. if( day == 0 || day < 0)
  23. break;
  24.  
  25. sprintf(day_str , "%2d" , day);
  26. read_line(msg_str, MSG_LEN);
  27.  
  28. for(i=0; i < num_remind; i++)
  29. if(strcmp(day_str , reminders[i]) < 0 )
  30. break;
  31.  
  32. for(j=num_remind; j>i; j--)
  33. strcpy(reminders[j], reminders[j-1]);
  34.  
  35. strcpy(reminders[i] , day_str);
  36. strcat(reminders[i] , msg_str);
  37.  
  38. num_remind++;
  39. }
  40.  
  41. if( !num_remind )
  42. exit(1);
  43.  
  44. printf("\nDay Reminder\n");
  45.  
  46. for(i=0; i < num_remind; i++)
  47. printf(" %s\n" , reminders[i]);
  48.  
  49. return 0;
  50. }
  51. //----------------------------------------------------------------------
  52. int read_line(char str[] , int n)
  53. {
  54. int ch , i =0 ;
  55.  
  56. while( (ch= getchar()) !='\n' && i<n)
  57. str[i++]= ch;
  58.  
  59. str[i]='\0';
  60.  
  61. return i;
  62. }
  63. //----------------------------------------------------------------------
  64.  
  65.  
Runtime error #stdin #stdout 0.01s 1724KB
stdin
Standard input is empty
stdout
 Enter day and reminder :