Bonjour,
J'ai une question sur un exercice dans lequel on travaille sur un tableau de chaine de caractere (donc j'ai compris qu'il faut utiliser un tableau de pointeur sur des char).Dans le traitement de ce tableau, on retrouve la supression et l'ajout d'une chaine de caractere dans le tableau.
De meme, une condition de l'exercice me dis que dans le cas ou mon tableau de chaine de caractere n'a plus de place(sachant que ce tableau a été alloué dynamiquement), on l'agrandit de 5 cases et que s'il posséde 7 cases libres alors on le retrecit de 5 cases.
J'ai plusieurs erreurs de compilation mais je n'arrive pas à comprendre, je vous met le code de mon programme :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
#include <iostream>
using namespace std;
 
const int SIZE=200;
int main()
{
	char letter;
	int choice,free=0,count=0,index,i,j,k;//numChar,numChar1,
	float temp;
	bool found;
	while(1)
	{
		cout<<"1.Enter a new string"<<endl
			<<"2.Delete a string"<<endl
			<<"3.Search a string"<<endl
			<<"4.Print all word which begin by the letter you'll choice"<<endl
			<<"5.Print all words of all strings"<<endl
			<<"6.Exit"<<endl
			<<"Enter your choice : ";
		cin>>choice;
		switch (choice)
		{
		case 1:if (free==0)
			   {
				   for(i=0;i<5;++i)
				   {
					   char * *(p+count+i);
					   *(p+count+i)=new * char;
					   p+count+i=NULL;
				   }
				   free=free+5;
			   }
			/*
			cout<<"How many characters has your string : ";
			cin>>temp;
			while (temp-(int)temp!=0 || temp<=0)
			{
				cout<<"Integer and strictly positive number please. Enter again : ";
				cin>>temp;
			}
			numChar=(int)temp; 
			*/
			*(p+count)=new char[SIZE];
			gets(*(p+count));
			++count;
			--free;
			break;
		case 2:
			for (j=0;j<count;++j)
			{
				puts(*(p+j));
				cout<<endl;
			}
			cout<<"What is the index of the string that you want to delete : ";
			cin>>temp;
			while(temp-(int)temp!=0 || temp<0 || temp>=count)
			{
				cout<<"Wrong value. Enter again : ";
				cin>>temp;
			}
			index=(int)temp;
			delete *(p+index)[];
			*(p+index)=NULL;
			for (int i=index;i<count-1;++i)
				*(p+i)=*(p+i+1);
			*(p+count-1)=NULL;
			--count;
			++free;
			if (free>=7)
			{
				for (i=0;i<5;++i)
					delete p+count+free-1-i[]; 
				free=free-5;
			}
            break;
		case 3:/*
			cout<<"How many characters has the string you're searching : ";
			cin>>temp;
			while (temp-(int)temp!=0 || temp<=0)
			{
				cout<<"Integer and strictly positive number please. Enter again : ";
				cin>>temp;
			}
			numChar1=(int)temp;
			*/
			cout<<"Enter the string you're searching : ";
		    char str[SIZE];
			// str=new char[numChar1];
			gets(str);
			for (j=0;j<count;++j)
			{
				found=true;
				if (strlen(str)==strlen(*(p+j)))
				{
					for (i=0;i<strlen(str);++i)
						if (*(*(p+j)+i) != *(str+i))
						{
							found=false;
							break;
					    }
				}
				else found=false;
				if (found)
					break;
			}
			if (j==count)
				cout<<"The string isn't in the board"<<endl;
			else
				cout<<"The string's index in the board is "<<j<<endl;
			break;
		case 4:
			cout<<"Enter the letter : ";
			cin>>letter;
			for (j=0;j<count;++j)
				for(i=0;i<strlen(*(p+j));++i)
				{
					if (i==0)
					{
						if(**(p+j)==letter)
						{
							for(k=0;*(*(p+j)+k)!=' ' && *(*(p+j)+k)!='\0';++k)
								cout<<*(*(p+j)+k);
							cout<<endl;
						}
                    }
					else
						if(*(*(p+j)+i)==letter && *(*(p+j)+i-1)==' ')
						{
							for(k=i;*(*(p+j)+k)!=' ' && *(*(p+j)+k)!='\0';++k)
								cout<<*(*(p+j)+k);
							cout<<endl;
						}
				}
				break;
		case 5:
			for (j=0;j<count;++j)
				for(i=0;i<strlen(*(p+j));++i)
				{
					if (i==0)
					{
						for(k=0;*(*(p+j)+k)!=' ' && *(*(p+j)+k)!='\0';++k)
								cout<<*(*(p+j)+k);
						cout<<endl;
					}
					else
					{
						for(k=i;*(*(p+j)+k)!=' ' && *(*(p+j)+k)!='\0';++k)
							cout<<*(*(p+j)+k);
						cout<<endl;
					}
				}
				break;
		case 6:
			return 0;
			}
			}
			}
Merci
Ne pas tenir compte des commentaires c'est l'ancienne version de ce que j'ai fais avant modification.