I don’t know how to pass the vector to main and manipulate it

Asked

Viewed 18 times

-1

Read a string with up to 100 characters and make a function that receives the string and returns how many words there are in the string. Create a second function to count how many letters there are in each word of the string, storing that count in an array passed by parameter to the function (this vector will have the number of words of the string). In the sequence, create an array with 2 columns and the number of rows equal to the size of the vector. In the first column of the matrix store the element of the vector and in the second column of the matrix store the amount of splitters that this element has.

#include <stdlib.h>
#include <string.h>
int contadorP(char string[100]);
void contadorL(char string[100]){
   int i, cont, j, vet[contadorP(string)];
   j=0;
   i=0;
   cont=0;
   while(string[i] != '\0'){
       cont++;
       if(string[i]==' ' ){
         vet[j]=cont-1;
         cont=0;
           j++;
         }
         if(string[i+1]=='\0'){
           vet[j]=cont;
         cont=0;
           j++;
         }
         i++;
   }
}

int main(void){
   char string[100], rep;
   int matriz[contadorP(string)][2], i, j;

       printf("informe uma string: ");
       gets(string);
       printf("A string tem %d palavras", contadorP(string));
       printf("\n=== VETOR ===\n");
       contadorL(string);
       for(i = 0; i < contadorP(string); i++)
      {
         printf("%d\t", * (vet));
      }

       printf("\n=== MATRIZ ===\n");
       printf("VALOR    QTDE DIVISORES");
       for(i=0;i<contadorP(string);i++){
           for(j=0;j<2;j++){

           }
       }


}

int contadorP(char string[100]){
   int cont=0, i=0, x=0;
    while(string[i] != '\0')
       {
           if(string[i] != ' ' && x == 0)
           {
               cont++;
               x = 1;
           }
           else if(string[i] == ' ')
           {
               x = 0;
           }
           i++;
       }
       return(cont);
}

  • Please edit the question to limit it to a specific problem with sufficient detail to identify an appropriate answer.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.