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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char text[20][80];
int main()
{
int i=0, num;
char c[80];
char e;
char car;
char temp[80];
FILE *g;
do {
printf("Entrer le nom de fichier a editer :\n");
fgets(c, sizeof(c), stdin);
c[strlen(c)-1] = 0;
g = fopen(c, "r");
if(g == NULL)
{
printf("Erreur le fichier n'existe pas\n");
}
}
while(g == NULL) ;
while(fgets (text[i], 80, g) !=NULL)
i++;
fclose(g);
system("clear");
printf("Que voulez-vous faire ? : ");
scanf(" %c", &e);
sscanf(temp, "%d", &num);
switch(e)
{
case 'A': /*Affichage du texte*/
for(i=0; i<20; i++)
printf("%s", text[i]);
break;
case 'm': /*Modification d'une ligne*/
fgets(temp, sizeof(temp), stdin);
printf ("Quelle ligne ? ");
sscanf(temp, "%d", &num);
fgets(text[num],80,stdin);
break;
case 'd': /*Suppression d'une ligne*/
printf ("Quelle ligne ? ");
sscanf(temp, "%d", &num);
fgets(temp, sizeof(temp), stdin);
for(i=18; i<num; i++)
strcpy(text[i], text[i+1]);
break;
case 'i': /*Insertion avant une ligne*/
printf ("Quelle ligne ? ");
sscanf(temp, "%d", &num);
fgets(temp, sizeof(temp), stdin);
for(i=19; i>num; i--)
strcpy(text[i], text[i-1]);
break;
case 'B': /*Sauver les modifications*/
break;
case 'a': /*Affichage d'une ligne*/
break;
case 'N': /*Affichage du texte avec les numéros de ligne*/
break;
case 's': /*Remplacement dans tous le texte d'un mot par un autre*/
break;
case 'I': /*Insertion en fin de texte*/
break;
case 'f': /*Affichage de toutes les lignes contenant un mot*/
break;
default:
printf("Erreur ce choix ne fait pas partie de ceux proposes \n");
break;
}
printf ("Autre chose a faire ? ");
scanf (" %c", &car);
while ((car != 'o')&&(car != 'n'))
{
printf ("Repondez par o ou n!\n Autre chose a faire ? (o/n) ");
scanf (" %c", &car);
}
while (car == 'o')
{
printf("Que voulez-vous faire ? : ");
scanf(" %c", &e);
switch(e)
{
case 'A': /*Affichage du texte*/
for(i=0; i<20; i++)
printf("%s", text[i]);
break;
case 'm': /*Modification d'une ligne*/
fgets(temp, sizeof(temp), stdin);
printf ("Quelle ligne ? ");
sscanf(temp, "%d", &num);
fgets(text[num],80,stdin);
break;
case 'd': /*Suppression d'une ligne*/
printf ("Quelle ligne ? ");
sscanf(temp, "%d", &num);
fgets(temp, sizeof(temp), stdin);
for(i=18; i<num; i++)
strcpy(text[i], text[i+1]);
break;
case 'i': /*Insertion avant une ligne*/
printf ("Quelle ligne ? ");
sscanf(temp, "%d", &num);
fgets(temp, sizeof(temp), stdin);
for(i=19; i>num; i--)
strcpy(text[i], text[i-1]);
break;
case 'B': /*Sauver les modifications*/
break;
case 'a': /*Affichage d'une ligne*/
break;
case 'N': /*Affichage du texte avec les numéros de ligne*/
break;
case 's': /*Remplacement dans tous le texte d'un mot par un autre*/
break;
case 'I': /*Insertion en fin de texte*/
break;
case 'f': /*Affichage de toutes les lignes contenant un mot*/
break;
default:
printf("Erreur ce choix ne fait pas partie de ceux proposes \n");
break;
}
printf ("Autre chose a faire ? ");
scanf (" %c", &car);
}
if (car == 'n')
{
return 0;
}
return 0;
} |
Partager