Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- void ler(char*** str, int* indice) {
- int flag = 1;
- while (flag) {
- (*str)[*indice] = (char*)malloc(1000 * sizeof(char));
- if ((*str)[*indice] == NULL) {
- printf("deu errado essa porra ae");
- flag = 0;
- }
- printf("digite a string: \n");
- if (fgets((*str)[*indice], 1000, stdin) != NULL) {
- if ((*str)[*indice][0] == '\n') {
- flag = 0;
- }
- else {
- (*str)[*indice][strcspn((*str)[*indice], "\n")] = '\0';
- (*indice)++;
- *str = realloc(*str, (*indice + 1) * sizeof(char*));
- if (*str == NULL) {
- printf("\n deu ruim isso aí ein\n");
- flag = 0;
- }
- }
- }
- else {
- flag = 0;
- }
- }
- }
- int main(){
- char** str = NULL;
- str = (char**)malloc(1 * sizeof(char*)); //malocando a quantidade de strings
- if(str == NULL){
- printf("\ndeu mto ruim saporra\n");
- }
- int indice = 0;
- ler(&str, &indice);
- printf("\naí as strings\n\n");
- for(int i = 0 ; i < indice ; i++){
- printf("\n%s", str[i]);
- free(str[i]);
- }
- free(str);
- printf("\n\naté mais...\n\n");
- return 0;
- }
Add Comment
Please, Sign In to add comment