Created
December 15, 2016 14:20
-
-
Save jeffotoni/852c7b87fb9d4a6ed2870f474f12861c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @abstract: brincando com strings | |
* @jeffotoni | |
* @exemplo strings | |
* @date: 2016 | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define MAX 5 | |
/** somente testes de declarcoes */ | |
typedef char string[]; | |
typedef char *string10[]; | |
typedef char *string20; | |
int main(){ | |
char *string1 = "abacate"; | |
char *vets[] = {"C","C++","NASM","PHP", "GO", "RUST", "JAVASCRIPT", "STOP", " "}; | |
int i; | |
int tamanho = strlen(string1) + 1; | |
char **array = (char**) malloc(tamanho*sizeof(char*)); | |
array[0] = string1; | |
array[1] = string1; | |
printf("\n array: %s", array[0]); | |
printf("\n array: %s", array[1]); | |
puts(""); | |
char *string2 = "linguagem"; | |
char *array2[MAX]; | |
tamanho = strlen(string2) + 1; | |
for(i = 0; i < MAX; i++){ | |
array2[i] = (char*) malloc(tamanho*sizeof(char)); | |
strcpy(array2[i], string2); | |
printf("\n array2[%d] : %s", i, array2[i]); | |
} | |
puts(""); | |
char *array3[7]; | |
for (i = 0; i < 7; i++){ | |
tamanho = strlen(vets[i]) + 1; | |
array3[i] = (char*) malloc(tamanho*sizeof(char)); | |
strcpy(array3[i], vets[i]); | |
} | |
///listando o vetor.. | |
for (i = 0; i < 7; i++) { | |
printf("\n array3[%d] : %s", i, array3[i]); | |
} | |
puts(""); | |
///listando vetor | |
char **ptr2 = vets; | |
i = 0 ; | |
while( **ptr2++ ){ | |
printf("\n vets:[%d]-> %s ", i, (*ptr2)++ ); | |
i++; | |
} | |
static int a[]={0,1,2,3,4}; | |
static int *p[]={a, a+1, a+2, a+3, a+4}; | |
int **ptr; | |
ptr =p; | |
**ptr++; | |
printf("\n%d %d %d", ptr-p, *ptr-a, **ptr); | |
*++*ptr; | |
printf("\n%d %d %d", ptr-p, *ptr-a, **ptr); | |
++**ptr; | |
printf("\n%d %d %d", ptr-p, *ptr-a, **ptr); | |
//memset(ptr, 0, 3 * 4 * sizeof(char*)); | |
puts(""); | |
free(array); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment