1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
typedef char *string;
typedef enum {ADD=1,MOVE,REMOV,DELET,DELETALL,SAVE,END} todo_t;
//typedef enum {monday,tuesday,wednesday,thursday,friday,saturday,sunday} day;
char days[7][10]={"monday","tuesday","wednesday","thursday","friday","saturday","sunday"};
char months[12][12]={"january","february","march","april","mai","june","july","august","september","october","november","december" };
const int daymax=31;
static void purge( void)
{
char c;
while ( ((c=getchar()) != '\n') && (c!=EOF) )
{};
}
static void clean(char *chaine)
{
char *p=strchr(chaine,'\n');
if (p)
*p='\0';
else purge();
}
struct date
{
int d;
char m[11];
unsigned int y;
};
struct client
{
int num;
char name[50],street[60];
struct date limit;
struct client *prev,*next;
};
int fileexist(FILE *liste1)
{
if ( ( liste1=fopen("C:\Programing\file02.doc","a+") )== NULL )
{
liste1=fopen("C:\Programing\file02.doc","a+");
//fprintf(liste1,"Client List :\n Name\t\t Address \t\t\t\t Delay\t\t\t\n");
printf("return 1\n");
return 1;
}
else return 0;
};
void angabe(struct client *var,FILE *liste1)
{
char c;
char str[3],str1[5];
printf("type a name please :");
fgets(var->name,50,stdin);
clean(var->name);
fprintf(liste1,"\n%d- %s \t",var->num,var->name);
printf("type the address of the client : ");
fgets(var->street,sizeof(var->street),stdin);
clean(var->street);
fprintf(liste1,"%s \t",var->street);
printf("give the delay for his/her payment :\nday :");
//scanf("%lu",&(var->limit.d));
fgets(str,2,stdin);
clean(str);
var->limit.d=string2int1(str,strlen(str));
fprintf(liste1,"%d \t",var->limit.d);
printf("; month : ");
fgets(var->limit.m,sizeof(var->limit.m),stdin);
clean(var->limit.m);
//scanf("%s",var->limit.m);
fprintf(liste1,"%s \t",var->limit.m);
printf("; year : ");
fgets(str,4,stdin);
//scanf("%lu",&(var->limit.y));
clean(str);
var->limit.y=string2int1(str,strlen(str));
fprintf(liste1,"%d \t",var->limit.y);
printf(";\n");
};
int main(void)
{
char todo[15],*char1=malloc(sizeof(char));
todo_t val1;
int t9;
FILE *liste;
struct client *first,*last,*var1,*temp,*var;
temp=malloc(sizeof(struct client));
printf(" CREATING A NEW LIST\n");
printf("Available Action : choose between add/remov/delet/deleteall/save/end\n");
do
{
int z11;
printf("choose an Action : ");
//scanf("%s",&todo);
fgets(todo,sizeof(todo),stdin);
clean(todo);
val1=(todo_t) strtol(todo,NULL,10);
printf("todo=%s->%ld val1=%d\n",todo,strtol(todo,NULL,10),val1);
switch (val1 )
{
//typedef enum {ADD=1,MOVE,REMOV,DELET,DELETALL,SAVE,END} todo_t;
case ADD : //if ( !strcmp(todo,"add") )
{
printf("ADD");
z11=fileexist(liste);
/*angabe(temp,liste);
if ( first)
{}
else
{
temp->num=0;
first=temp;
last=temp;
}*/
free(temp);
//fclose(liste);
//printf("z11=%d",z11);
}; break;
case REMOV : break;
default :
if ( strcmp(todo,"END")!=0 )
printf("please try again\n");
}
} while( strcmp(todo,"END")!=0);
} |
Partager