Ir para conteúdo
Fórum Script Brasil

Felipe_JDES

Membros
  • Total de itens

    2
  • Registro em

  • Última visita

Sobre Felipe_JDES

Felipe_JDES's Achievements

0

Reputação

  1. #include <stdio.h> #include <string.h> #include <stdlib.h> typedef struct TChar { char value; struct TChar *next; } Char; typedef struct TString { Char *first; int size; } String; String* newString(void){ String *s = (String*) malloc (sizeof(String)); s->size = 0; s->first = NULL; return s; } void StringWriting(String *str){ Char *tmp = str->first; while (tmp != NULL) { printf("%c", tmp->value); tmp = tmp->next; } printf("\n"); } void StringAppend(String *str, char c) { if (str->size == 0) { str->first = (Char*) malloc (sizeof(Char)); str->first->value = c; str->size++; } else { Char *tmp = str->first; while (tmp->next != NULL) { tmp = tmp->next; } Char *novo = (Char*) malloc (sizeof(Char)); novo->value = c; novo->next = NULL; tmp->next = novo; str->size++; } } void StringReadLine(String *str) { char c = getchar(); while (c != '\n'){ StringAppend(str, c); c = getchar(); } } void StringAddAll(String *s, char a[], int n){ int i; for(i=0; i<n; i++){ StringAppend(s, a); } s->size = s->size+n; } int main(){ String *str = newString(); StringReadLine(str); char a[] = {", Ola"}; StringAddAll(str, a, strlen(a)); StringWriting(str); }
  2. preciso resolver essa questão qual a maneira mais simples para fazer esse metodos em linguagem C? Crie a função stringAddall que recebe um ponteiro para uma string como primeiro argumento e um vetor de caracteres como segundo argumento. A função deve adicionar todos os caracteres do vetor de caracteres no final da string dado como primeiro argumento. O protótipo da função deve ter o seguinte formato: Void stringAddAll(String *s, char a[], int n){ //implementação aqui } observe que n é a quantidade de caracteres no vetor a.
×
×
  • Criar Novo...