dynamic alocate pointer to pointer on array by dzury

dynamic alocate pointer to pointer on two dimensional array

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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297

/* Convert Decimal to Binary */

int main() {
    int binary[100];

    printf("Enter any decimal number: ");
    int n;
    scanf("%d", &n);

    int i=0;
    int quotient = n;
    while (quotient != 0) {
        binary[i] = quotient % 2;
        quotient = quotient / 2;
        i++;
    }

    i--;
    printf("Equivalent binary number is: ");
    while (i>=0) {
        printf("%d", binary[i]);
        i--;
    }

    getch();
    return 0;
}

 
#include <stdio.h>

int main() {

    long int binaryNumber, decimalNumber=0;
    long int j=1, remainder;

    printf("Enter any number any binary number: ");
    scanf("%ld", &binaryNumber);

    while (binaryNumber!=0) {
        remainder = binaryNumber%10;
        decimalNumber = decimalNumber + remainder*j;
        j = j*2;
        binaryNumber = binaryNumber / 10;
    }

    printf("Equivalent decimal value: %ld", decimalNumber);

    getch();
    return 0;
}





int **vytvor_pole(int riadky, int stlpce)

{

	int **p_p_x, i;



	p_p_x = (int **) malloc(riadky * sizeof(int *));

	for (i = 0; i < riadky; i++)

		p_p_x[i] = (int *) malloc(stlpce * sizeof(int));



	return(p_p_x);

}



void uvolni_pole(int **p_p_x, int riadky)

{

	int i;

	

	for (i = 0; i < riadky; i++)

		free((void *) p_p_x[i]);



	free((void *) p_p_x);

}







#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
/*
 * 
 */
void parse(char *string){ //pomocou funkcie strtok rozparsuje retazec slov oddelenych medzerov 
  char *token;
    char *znak;
    znak=" ";
     token=(char *)malloc(10);
     int i=0,a=0, dlzka=0 ;
     while(string[a]!='\0'){
         if(string[a]==' '){dlzka++;}
         a++;         
     }
     token=strtok(string,znak);
    printf("%s\n",token);
    while(i!=dlzka){
   
    token=strtok(NULL,znak);
    printf("%s\n",token);
    i++;
    }
}

char *parses(char *retazec){
    char *prem;
    prem=(char *)malloc(20);
    int i=0;
    while(retazec[i]!='\0'){
        if(retazec[i]==' ') { retazec[i]='\n';}
        i++;
    }  
    strcpy(prem,retazec);
    return prem;

}

char *reverz(char *retazec){ //funkcia otoci retazec 
  char *reverz, dlzka;
    reverz=malloc(strlen(retazec)+1);
    dlzka=strlen(retazec);
    int i;
    for(i=0; i<dlzka; i++){
        reverz[i]=retazec[dlzka-i-1];
    
    }
    reverz[i]='\0';
    return reverz;
    
}

int *change(char *retazec){ //funkcia zmeni v kazdom slove prve pismeno male<->velke
    char *string,c;  int i=0;
    string=(char *)malloc(20);
  
   c=retazec[0];
      if(isupper(c)) { c=tolower(c);  retazec[i]=c;}
          else if (islower(c)) { c=toupper(c);  retazec[i]=c;}
   
    while(retazec[i]!='\0'){
      if(retazec[i]==' ') {
          c=retazec[++i];
      if(isupper(c)) { c=tolower(c);  retazec[i]=c;}
          else if (islower(c)) { c=toupper(c);  retazec[i]=c;}
      }  
      i++;
    }
    strcpy(string,retazec); 
    

    return (int*)string;
    
}

void strdel(char *s, int i, int n) {    //  vymaže z reťazca s n znakov od pozície i vrátane. 
    char *string; int poz=0, a=0,prem;
    string=(char *)malloc(20);
    while(s[a]!='\0'){
           string[poz]=s[a];
           a++; poz++;
        if((a+1)==i){ 
            for(prem=0;prem<n;prem++)
            a++;  }
           
    }
    string[poz]='\0';
    strcpy(s,string);
    puts(string);            
}

void matica(int m,int n){ //vztvori pole mxn a naplni ho postupne cislami
  // int pole[9][9],
          int i,j=0,c=0;
   int **pole;
 pole=(int **)malloc(m*sizeof(int *)); //pocet stlpcov 
 for(i=0;i<m;i++)               //pocet riadkov
pole[i]=(int *)malloc(sizeof(int)*n);    //dlzka jedneho riadku
 
   for(i=0;i<n;i++){
       for(j=0;j<m;j++){
           pole[i][j]=c++;
       }
       //pole[i][j]=i;
   } 
   for(i=0;i<n;i++){
       for(j=0;j<m;j++){
           if(pole[i][j]<10) printf("  %d ",pole[i][j]);
           else  printf(" %d ",pole[i][j]);
       }
       printf("\n");
   } 
  for(i=0;i<n;i++){ free(pole[i]); }
free(pole);
}

void poleretazcov(char *path,int *riadky){   //nacita kazde slovo do pola retazcov 
     FILE *f; 
     //int i=0;
     f=fopen(path,"r");
     if(f==NULL) printf("nepodarilo sa otvorit");
     char **slovo,znak[10]; 
     int i=0;
     slovo=(char**)malloc(sizeof(char*)*105);    
    
    while(fscanf(f,"%s",znak)!=EOF){
        
         slovo[i]=(char *)malloc(strlen(znak)+1);
         strcpy(slovo[i],znak);
         i++; 
                 
     }
     *riadky=i;
     int b,a; char temp[30];
       for(b=0;b<i;b++){      //buble sort podla abecedy
      for(a=0;a<i;a++){
          if(strcmp(slovo[a],slovo[b])<0){
              strcpy(temp,slovo[b]);
              strcpy(slovo[b],slovo[a]);
              strcpy(slovo[a],temp);
          }
      }  
                      }
    i--; 
       
   while(i>=0){
    printf("%d-%s\n",i,slovo[i]); 
     i--; 
    } 
         //free(slovo);
        // return (*slovo);
 }
 
int main(int argc, char** argv) {
/**
    char *slova;
    slova=(char *)malloc(100);
   
    gets(slova);
  
    printf("%s\n",slova);
   // parse(slova);
    char *ptr;
   ptr=reverz(slova);
      printf("otoceny retazec  %s\n ",ptr);
      
    //  ptr=parses(slova);
    //  printf("parse\n %s\n ",ptr);
      
    //    ptr=change(slova);
      //printf(" %s\n ",ptr);
      
      strdel(slova,5,3);
    
      free(ptr);
     
    
   
  */       
    int *i;
  poleretazcov("words.txt",i);
  printf("\n%d",*i);
/**
    char *ptr;
    printf(" %s\n ",slova);
   ptr=(char*)change(slova);
  printf("%s\n ",ptr);
*/  
  //   matica(10,10); //pocet stlpcov x pocet riadkov
    return (EXIT_SUCCESS);
}
Last edited on
Topic archived. No new replies allowed.